Preventing hangups in bgworker start/stop during DB shutdown
Tom Lane <tgl@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-hackers@lists.postgresql.org
Date: 2020-12-22T21:40:26Z
Lists: pgsql-hackers
Attachments
- cancel-unserviced-worker-requests-1.patch (text/x-diff) patch
Here's an attempt at closing the race condition discussed in [1] (and in some earlier threads, though I'm too lazy to find them). The core problem is that the bgworker management APIs were designed without any thought for exception conditions, notably "we're not gonna launch any more workers because we're shutting down the database". A process waiting for a worker in WaitForBackgroundWorkerStartup or WaitForBackgroundWorkerShutdown will wait forever, so that the database fails to shut down without manual intervention. I'd supposed that we would need some incompatible changes in those APIs in order to fix this, but after further study it seems like we could hack things by just acting as though a request that won't be serviced has already run to completion. I'm not terribly satisfied with that as a long-term solution --- it seems to me that callers should be told that there was a failure. But this looks to be enough to solve the lockup condition for existing callers, and it seems like it'd be okay to backpatch. Thoughts? regards, tom lane [1] https://www.postgresql.org/message-id/flat/16785-c0207d8c67fb5f25%40postgresql.org
Commits
-
Fix race condition between shutdown and unstarted background workers.
- b99b6b9d6cac 11.11 landed
- 7519bd16d1a2 14.0 landed
- 3d8068edce13 12.6 landed
- 1a6b1c460b4f 10.16 landed
- 0217ad806637 13.2 landed