]> granicus.if.org Git - postgresql/commit
Make WaitLatchOrSocket's timeout detection more robust.
authorTom Lane <tgl@sss.pgh.pa.us>
Sat, 18 Jul 2015 15:47:13 +0000 (11:47 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Sat, 18 Jul 2015 15:47:13 +0000 (11:47 -0400)
commit498a29dc32f34e6936d456e95a0beb44a9c3b637
tree4a3e37e49ff6965d4ce01d4bc638bd22e09b28bb
parent7319c0524d66b00a711db7f560d6a34051739e35
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.)
src/backend/port/unix_latch.c
src/backend/port/win32_latch.c