pgsql: Make WaitLatchOrSocket's timeout detection more robust.

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)postgresql(dot)org
Subject: pgsql: Make WaitLatchOrSocket's timeout detection more robust.
Date: 2015-07-18 15:47:33
Message-ID: E1ZGUKr-00070M-3E@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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_5_STABLE

Details
-------
http://git.postgresql.org/pg/commitdiff/fd735e976cab3a95374c710ff5d2865102e3145a

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

Browse pgsql-committers by date

  From Date Subject
Next Message Andrew Dunstan 2015-07-19 17:21:01 pgsql: Remove dead code.
Previous Message Andrew Dunstan 2015-07-18 14:11:43 pgsql: Enable transforms modules to build and test on Cygwin.