Re: Restart pg_usleep when interrupted - Mailing list pgsql-hackers

From Sami Imseih
Subject Re: Restart pg_usleep when interrupted
Date
Msg-id 521A6F3B-77E1-4F3F-B15E-BCF26D52C698@gmail.com
Whole thread Raw
In response to Re: Restart pg_usleep when interrupted  (Nathan Bossart <nathandbossart@gmail.com>)
Responses Re: Restart pg_usleep when interrupted
List pgsql-hackers

What does your testing show when you don't have
the extra check, i.e.,

struct timespec delay;
struct timespec remain;

delay.tv_sec = microsec / 1000000L;
delay.tv_nsec = (microsec % 1000000L) * 1000;

while (nanosleep(&delay, &remain) == -1 && errno == EINTR)
delay = remain;


This is similar to the first attempt [1], 

+pg_usleep_handle_interrupt(long microsec, bool force)
 {
    if (microsec > 0)
    {
 #ifndef WIN32
        struct timespec delay;
+       struct timespec remaining;
 
        delay.tv_sec = microsec / 1000000L;
        delay.tv_nsec = (microsec % 1000000L) * 1000;
-       (void) nanosleep(&delay, NULL);
+
+       if (force)
+           while (nanosleep(&delay, &remaining) == -1 && errno == EINTR)
+               delay = remaining;


but Bertrand found long drifts [2[ which I could not reproduce.
To safeguard the long drifts, continue to use the &remain time with an 
additional safeguard to make sure the actual sleep does not exceed the 
requested sleep time.

[1] https://www.postgresql.org/message-id/7D50DC5B-80C6-47B5-8DA8-A6C68A115EE5%40gmail.com


Regards,

Sami 

pgsql-hackers by date:

Previous
From: Daniel Gustafsson
Date:
Subject: Re: Add support to TLS 1.3 cipher suites and curves lists
Next
From: Daniel Gustafsson
Date:
Subject: Re: Internal error codes triggered by tests