Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit f0b7ab7

Browse files
committed
postmaster: Don't repeatedly transition to crashing state
Previously HandleChildCrash() skipped logging and signalling child exits if already in an immediate shutdown or in FatalError state, but still transitioned server state in response to a crash. That's redundant. In the other place we transition to FatalError, we do take care to not do so when already in FatalError state. To make it easier to combine different paths for entering FatalError state, only do so once in HandleChildCrash(). Reviewed-by: Bertrand Drouvot <bertranddrouvot.pg@gmail.com> Discussion: https://postgr.es/m/kgng5nrvnlv335evmsuvpnh354rw7qyazl73kdysev2cr2v5zu@m3cfzxicm5kp
1 parent d239c1a commit f0b7ab7

File tree

1 file changed

+8
-14
lines changed

1 file changed

+8
-14
lines changed

src/backend/postmaster/postmaster.c

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2685,24 +2685,20 @@ CleanupBackend(PMChild *bp,
26852685
static void
26862686
HandleChildCrash(int pid, int exitstatus, const char *procname)
26872687
{
2688-
bool take_action;
2689-
26902688
/*
26912689
* We only log messages and send signals if this is the first process
26922690
* crash and we're not doing an immediate shutdown; otherwise, we're only
26932691
* here to update postmaster's idea of live processes. If we have already
26942692
* signaled children, nonzero exit status is to be expected, so don't
26952693
* clutter log.
26962694
*/
2697-
take_action = !FatalError && Shutdown != ImmediateShutdown;
2695+
if (FatalError || Shutdown == ImmediateShutdown)
2696+
return;
26982697

2699-
if (take_action)
2700-
{
2701-
LogChildExit(LOG, procname, pid, exitstatus);
2702-
ereport(LOG,
2703-
(errmsg("terminating any other active server processes")));
2704-
SetQuitSignalReason(PMQUIT_FOR_CRASH);
2705-
}
2698+
LogChildExit(LOG, procname, pid, exitstatus);
2699+
ereport(LOG,
2700+
(errmsg("terminating any other active server processes")));
2701+
SetQuitSignalReason(PMQUIT_FOR_CRASH);
27062702

27072703
/*
27082704
* Signal all other child processes to exit. The crashed process has
@@ -2711,11 +2707,9 @@ HandleChildCrash(int pid, int exitstatus, const char *procname)
27112707
* We could exclude dead-end children here, but at least when sending
27122708
* SIGABRT it seems better to include them.
27132709
*/
2714-
if (take_action)
2715-
TerminateChildren(send_abort_for_crash ? SIGABRT : SIGQUIT);
2710+
TerminateChildren(send_abort_for_crash ? SIGABRT : SIGQUIT);
27162711

2717-
if (Shutdown != ImmediateShutdown)
2718-
FatalError = true;
2712+
FatalError = true;
27192713

27202714
/* We now transit into a state of waiting for children to die */
27212715
if (pmState == PM_RECOVERY ||

0 commit comments

Comments
 (0)