]> 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)
commit29efe1b5ebc82512cae363349bae6dd22e9b00eb
tree702a8aa5e7ad2b4c4eacc97db7645ddba2f03771
parentf3f037e187c601d76777ae10b10657a0c0d3299c
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