pgsql: Check for too many postmaster children before spawning a bgworke - Mailing list pgsql-committers

From Tom Lane
Subject pgsql: Check for too many postmaster children before spawning a bgworke
Date
Msg-id E1iHW2m-0004bJ-8M@gemulon.postgresql.org
Whole thread Raw
List pgsql-committers
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

Branch
------
REL9_5_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/8c2910ce5ed71fa1b70343627069000a4f6f1420

Modified Files
--------------
src/backend/postmaster/postmaster.c | 49 ++++++++++++++++++++++++++-----------
1 file changed, 35 insertions(+), 14 deletions(-)


pgsql-committers by date:

Previous
From: Peter Eisentraut
Date:
Subject: pgsql: Simplify PGAC_STRUCT_TIMEZONE Autoconf macro
Next
From: Bruce Momjian
Date:
Subject: pgsql: doc: move mention of log_min_error_statement in a better spot