8000 Fix autovacuum launcher shutdown sequence · rowhit/postgres@0d6c9e0 · GitHub
[go: up one dir, main page]

Skip to content
8000

Commit 0d6c9e0

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 b1145ca commit 0d6c9e0

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
@@ -534,6 +534,10 @@ AutoVacLauncherMain(int argc, char *argv[])
534534
/* Now we can allow interrupts again */
535535
RESUME_INTERRUPTS();
536536

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

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

@@ -587,7 +595,8 @@ AutoVacLauncherMain(int argc, char *argv[])
587595
*/
588596
rebuild_database_list(InvalidOid);
589597

590-
for (;;)
598+
/* loop until shutdown request */
599+
while (!got_SIGTERM)
591600
{
592601
struct timeval nap;
593602
TimestampTz current_time = 0;
@@ -787,6 +796,7 @@ AutoVacLauncherMain(int argc, char *argv[])
787796
}
788797

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

0 commit comments

Comments
 (0)
0