@@ -2674,40 +2674,35 @@ CleanupBackend(PMChild *bp,
2674
2674
}
2675
2675
2676
2676
/*
2677
- * HandleChildCrash -- cleanup after failed backend, bgwriter, checkpointer,
2678
- * walwriter, autovacuum, archiver, slot sync worker, or background worker.
2677
+ * Transition into FatalError state, in response to something bad having
2678
+ * happened. Commonly the caller will have logged the reason for entering
2679
+ * FatalError state.
2679
2680
*
2680
- * The objectives here are to clean up our local state about the child
2681
- * process, and to signal all other remaining children to quickdie.
2682
- *
2683
- * The caller has already released its PMChild slot.
2681
+ * This should only be called when not already in FatalError or
2682
+ * ImmediateShutdown state.
2684
2683
*/
2685
2684
static void
2686
- HandleChildCrash ( int pid , int exitstatus , const char * procname )
2685
+ HandleFatalError ( QuitSignalReason reason , bool consider_sigabrt )
2687
2686
{
2688
- /*
2689
- * We only log messages and send signals if this is the first process
2690
- * crash and we're not doing an immediate shutdown; otherwise, we're only
2691
- * here to update postmaster's idea of live processes. If we have already
2692
- * signaled children, nonzero exit status is to be expected, so don't
2693
- * clutter log.
2694
- */
2695
- if (FatalError || Shutdown == ImmediateShutdown )
2696
- return ;
2687
+ int sigtosend ;
2697
2688
2698
- LogChildExit (LOG , procname , pid , exitstatus );
2699
- ereport (LOG ,
2700
- (errmsg ("terminating any other active server processes" )));
2701
- SetQuitSignalReason (PMQUIT_FOR_CRASH );
2689
+ Assert (!FatalError );
2690
+ Assert (Shutdown != ImmediateShutdown );
2691
+
2692
+ SetQuitSignalReason (reason );
2693
+
2694
+ if (consider_sigabrt && send_abort_for_crash )
2695
+ sigtosend = SIGABRT ;
2696
+ else
2697
+ sigtosend = SIGQUIT ;
2702
2698
2703
2699
/*
2704
- * Signal all other child processes to exit. The crashed process has
2705
- * already been removed from ActiveChildList.
2700
+ * Signal all other child processes to exit.
2706
2701
*
2707
2702
* We could exclude dead-end children here, but at least when sending
2708
2703
* SIGABRT it seems better to include them.
2709
2704
*/
2710
- TerminateChildren (send_abort_for_crash ? SIGABRT : SIGQUIT );
2705
+ TerminateChildren (sigtosend );
2711
2706
2712
2707
FatalError = true;
2713
2708
@@ -2727,6 +2722,39 @@ HandleChildCrash(int pid, int exitstatus, const char *procname)
2727
2722
AbortStartTime = time (NULL );
2728
2723
}
2729
2724
2725
+ /*
2726
+ * HandleChildCrash -- cleanup after failed backend, bgwriter, checkpointer,
2727
+ * walwriter, autovacuum, archiver, slot sync worker, or background worker.
2728
+ *
2729
+ * The objectives here are to clean up our local state about the child
2730
+ * process, and to signal all other remaining children to quickdie.
2731
+ *
2732
+ * The caller has already released its PMChild slot.
2733
+ */
2734
+ static void
2735
+ HandleChildCrash (int pid , int exitstatus , const char * procname )
2736
+ {
2737
+ /*
2738
+ * We only log messages and send signals if this is the first process
2739
+ * crash and we're not doing an immediate shutdown; otherwise, we're only
2740
+ * here to update postmaster's idea of live processes. If we have already
2741
+ * signaled children, nonzero exit status is to be expected, so don't
2742
+ * clutter log.
2743
+ */
2744
+ if (FatalError || Shutdown == ImmediateShutdown )
2745
+ return ;
2746
+
2747
+ LogChildExit (LOG , procname , pid , exitstatus );
2748
+ ereport (LOG ,
2749
+ (errmsg ("terminating any other active server processes" )));
2750
+
2751
+ /*
2752
+ * Switch into error state. The crashed process has already been removed
2753
+ * from ActiveChildList.
2754
+ */
2755
+ HandleFatalError (PMQUIT_FOR_CRASH , true);
2756
+ }
2757
+
2730
2758
/*
2731
2759
* Log the death of a child process.
2732
2760
*/
0 commit comments