mirror of
https://github.com/postgres/postgres.git
synced 2025-09-02 04:21:28 +03:00
Fix WaitLatch() to return promptly when the requested timeout expires.
If the sleep is interrupted by a signal, we must recompute the remaining time to wait; otherwise, a steady stream of non-wait-terminating interrupts could delay return from WaitLatch indefinitely. This has been shown to be a problem for the autovacuum launcher, and there may well be other places now or in the future with similar issues. So we'd better make the function robust, even though this'll add at least one gettimeofday call per wait. Back-patch to 9.2. We might eventually need to fix 9.1 as well, but the code is quite different there, and the usage of WaitLatch in 9.1 is so limited that it's not clearly important to do so. Reported and diagnosed by Jeff Janes, though I rewrote his patch rather heavily.
This commit is contained in:
@@ -33,8 +33,8 @@
|
||||
* ResetLatch - Clears the latch, allowing it to be set again
|
||||
* WaitLatch - Waits for the latch to become set
|
||||
*
|
||||
* WaitLatch includes a provision for timeouts (which should hopefully not
|
||||
* be necessary once the code is fully latch-ified) and a provision for
|
||||
* WaitLatch includes a provision for timeouts (which should be avoided
|
||||
* when possible, as they incur extra overhead) and a provision for
|
||||
* postmaster child processes to wake up immediately on postmaster death.
|
||||
* See unix_latch.c for detailed specifications for the exported functions.
|
||||
*
|
||||
@@ -64,14 +64,15 @@
|
||||
* will be lifted in future by inserting suitable memory barriers into
|
||||
* SetLatch and ResetLatch.
|
||||
*
|
||||
* On some platforms, signals will not interrupt the latch wait primitive
|
||||
* by themselves. Therefore, it is critical that any signal handler that
|
||||
* is meant to terminate a WaitLatch wait calls SetLatch.
|
||||
*
|
||||
* Note that use of the process latch (PGPROC.procLatch) is generally better
|
||||
* than an ad-hoc shared latch for signaling auxiliary processes. This is
|
||||
* because generic signal handlers will call SetLatch on the process latch
|
||||
* only, so using any latch other than the process latch effectively precludes
|
||||
* ever registering a generic handler. Since signals have the potential to
|
||||
* invalidate the latch timeout on some platforms, resulting in a
|
||||
* denial-of-service, it is important to verify that all signal handlers
|
||||
* within all WaitLatch-calling processes call SetLatch.
|
||||
* use of any generic handler.
|
||||
*
|
||||
*
|
||||
* Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group
|
||||
|
Reference in New Issue
Block a user