]> granicus.if.org Git - postgresql/commit
Check for too many postmaster children before spawning a bgworker.
authorTom Lane <tgl@sss.pgh.pa.us>
Mon, 7 Oct 2019 16:39:09 +0000 (12:39 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Mon, 7 Oct 2019 16:39:09 +0000 (12:39 -0400)
commitc69e982a60fb5b67fb946300209460f35c19daf2
tree30b841838ee6c0bd1111b149da28b283f90055e0
parent639feb92e1186e1de495d1bfdb191869cb56450a
Check for too many postmaster children before spawning a bgworker.

The postmaster's code path for spawning a bgworker neglected to check
whether we already have the max number of live child processes.  That's
a bit hard to hit, since it would necessarily be a transient condition;
but if we do, AssignPostmasterChildSlot() fails causing a postmaster
crash, as seen in a report from Bhargav Kamineni.

To fix, invoke canAcceptConnections() in the bgworker code path, as we
do in the other code paths that spawn children.  Since we don't want
the same pmState tests in this case, add a child-process-type parameter
to canAcceptConnections() so that it can know what to do.

Back-patch to 9.5.  In principle the same hazard exists in 9.4, but the
code is enough different that this patch wouldn't quite fix it there.
Given the tiny usage of bgworkers in that branch it doesn't seem worth
creating a variant patch for it.

Discussion: https://postgr.es/m/18733.1570382257@sss.pgh.pa.us
src/backend/postmaster/postmaster.c