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

Commit ec01c1c

Browse files
committed
Fix autovacuum launcher shutdown sequence
It was previously possible to have the launcher re-execute its main loop before shutting down if some other signal was received or an error occurred after getting SIGTERM, as reported by Qingqing Zhou. While investigating, Tom Lane further noticed that if autovacuum had been disabled in the config file, it would misbehave by trying to start a new worker instead of bailing out immediately -- it would consider itself as invoked in emergency mode. Fix both problems by checking the shutdown flag in a few more places. These problems have existed since autovacuum was introduced, so backpatch all the way back.
1 parent f97a0a2 commit ec01c1c

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/backend/postmaster/autovacuum.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,10 @@ AutoVacLauncherMain(int argc, char *argv[])
533533
/* Now we can allow interrupts again */
534534
RESUME_INTERRUPTS();
535535

536+
/* if in shutdown mode, no need for anything further; just go away */
537+
if (got_SIGTERM)
538+
goto shutdown;
539+
536540
/*
537541
* Sleep at least 1 second after any error. We don't want to be
538542
* filling the error logs as fast as we can.
@@ -568,10 +572,14 @@ AutoVacLauncherMain(int argc, char *argv[])
568572
SetConfigOption("default_transaction_isolation", "read committed",
569573
PGC_SUSET, PGC_S_OVERRIDE);
570574

571-
/* in emergency mode, just start a worker and go away */
575+
/*
576+
* In emergency mode, just start a worker (unless shutdown was requested)
577+
* and go away.
578+
*/
572579
if (!AutoVacuumingActive())
573580
{
574-
do_start_worker();
581+
if (!got_SIGTERM)
582+
do_start_worker();
575583
proc_exit(0); /* done */
576584
}
577585

@@ -586,7 +594,8 @@ AutoVacLauncherMain(int argc, char *argv[])
586594
*/
587595
rebuild_database_list(InvalidOid);
588596

589-
for (;;)
597+
/* loop until shutdown request */
598+
while (!got_SIGTERM)
590599
{
591600
struct timeval nap;
592601
TimestampTz current_time = 0;
@@ -786,6 +795,7 @@ AutoVacLauncherMain(int argc, char *argv[])
786795
}
787796

788797
/* Normal exit from the autovac launcher is here */
798+
shutdown:
789799
ereport(LOG,
790800
(errmsg("autovacuum launcher shutting down")));
791801
AutoVacuumShmem->av_launcherpid = 0;

0 commit comments

Comments
 (0)