pgsql: Make WaitLatchOrSocket's timeout detection more robust. - Mailing list pgsql-committers

From Tom Lane
Subject pgsql: Make WaitLatchOrSocket's timeout detection more robust.
Date
Msg-id E1ZGUKr-00070S-3h@gemulon.postgresql.org
Whole thread Raw
List pgsql-committers
Make WaitLatchOrSocket's timeout detection more robust.

In the previous coding, timeout would be noticed and reported only when
poll() or socket() returned zero (or the equivalent behavior on Windows).
Ordinarily that should work well enough, but it seems conceivable that we
could get into a state where poll() always returns a nonzero value --- for
example, if it is noticing a condition on one of the file descriptors that
we do not think is reason to exit the loop.  If that happened, we'd be in a
busy-wait loop that would fail to terminate even when the timeout expires.

We can make this more robust at essentially no cost, by deciding to exit
of our own accord if we compute a zero or negative time-remaining-to-wait.
Previously the code noted this but just clamped the time-remaining to zero,
expecting that we'd detect timeout on the next loop iteration.

Back-patch to 9.2.  While 9.1 had a version of WaitLatchOrSocket, it was
primitive compared to later versions, and did not guarantee reliable
detection of timeouts anyway.  (Essentially, this is a refinement of
commit 3e7fdcffd6f77187, which was back-patched only as far as 9.2.)

Branch
------
REL9_3_STABLE

Details
-------
http://git.postgresql.org/pg/commitdiff/498a29dc32f34e6936d456e95a0beb44a9c3b637

Modified Files
--------------
src/backend/port/unix_latch.c  |   20 +++++++++++++-------
src/backend/port/win32_latch.c |    9 ++++++---
2 files changed, 19 insertions(+), 10 deletions(-)


pgsql-committers by date:

Previous
From: Tom Lane
Date:
Subject: pgsql: Make WaitLatchOrSocket's timeout detection more robust.
Next
From: Tom Lane
Date:
Subject: pgsql: Make WaitLatchOrSocket's timeout detection more robust.