Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHeikki Linnakangas2024-11-14 14:12:04 +0000
committerHeikki Linnakangas2024-11-14 14:12:04 +0000
commitbb861414fea31073f27aaab75a0ceaf3638d7985 (patch)
tree693850f21bff362d67ca7276d8cb73245653ae3f /src/backend
parent18d67a8d7d30884655d65910b82781d9360819a6 (diff)
Kill dead-end children when there's nothing else left
Previously, the postmaster would never try to kill dead-end child processes, even if there were no other processes left. A dead-end backend will eventually exit, when authentication_timeout expires, but if a dead-end backend is the only thing that's preventing the server from shutting down, it seems better to kill it immediately. It's particularly important, if there was a bug in the early startup code that prevented a dead-end child from timing out and exiting normally. Includes a test for that case where a dead-end backend previously prevented the server from shutting down. Reviewed-by: Andres Freund <andres@anarazel.de> Discussion: https://www.postgresql.org/message-id/a102f15f-eac4-4ff2-af02-f9ff209ec66f@iki.fi
Diffstat (limited to 'src/backend')
-rw-r--r--src/backend/postmaster/postmaster.c17
1 files changed, 9 insertions, 8 deletions
diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c
index b104f4b1152..b5300949843 100644
--- a/src/backend/postmaster/postmaster.c
+++ b/src/backend/postmaster/postmaster.c
@@ -2985,10 +2985,11 @@ PostmasterStateMachine(void)
if (Shutdown >= ImmediateShutdown || FatalError)
{
/*
- * Start waiting for dead_end children to die. This state
- * change causes ServerLoop to stop creating new ones.
+ * Stop any dead_end children and stop creating new ones.
*/
pmState = PM_WAIT_DEAD_END;
+ ConfigurePostmasterWaitSet(false);
+ SignalChildren(SIGQUIT, btmask(B_DEAD_END_BACKEND));
/*
* We already SIGQUIT'd the archiver and stats processes, if
@@ -3027,9 +3028,10 @@ PostmasterStateMachine(void)
*/
FatalError = true;
pmState = PM_WAIT_DEAD_END;
+ ConfigurePostmasterWaitSet(false);
/* Kill the walsenders and archiver too */
- SignalChildren(SIGQUIT, btmask_all_except(B_DEAD_END_BACKEND));
+ SignalChildren(SIGQUIT, BTYPE_MASK_ALL);
if (PgArchPID != 0)
signal_child(PgArchPID, SIGQUIT);
}
@@ -3048,14 +3050,13 @@ PostmasterStateMachine(void)
if (PgArchPID == 0 && CountChildren(btmask_all_except(B_DEAD_END_BACKEND)) == 0)
{
pmState = PM_WAIT_DEAD_END;
+ ConfigurePostmasterWaitSet(false);
+ SignalChildren(SIGTERM, BTYPE_MASK_ALL);
}
}
if (pmState == PM_WAIT_DEAD_END)
{
- /* Don't allow any new socket connection events. */
- ConfigurePostmasterWaitSet(false);
-
/*
* PM_WAIT_DEAD_END state ends when the BackendList is entirely empty
* (ie, no dead_end children remain), and the archiver is gone too.
@@ -3381,12 +3382,12 @@ SignalChildren(int signal, BackendTypeMask targetMask)
/*
* Send a termination signal to children. This considers all of our children
- * processes, except syslogger and dead_end backends.
+ * processes, except syslogger.
*/
static void
TerminateChildren(int signal)
{
- SignalChildren(signal, btmask_all_except(B_DEAD_END_BACKEND));
+ SignalChildren(signal, BTYPE_MASK_ALL);
if (StartupPID != 0)
{
signal_child(StartupPID, signal);