Skip to content

Commit cf5d3f2

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 c68b063 commit cf5d3f2

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

518+
/* if in shutdown mode, no need for anything further; just go away */
519+
if (got_SIGTERM)
520+
goto shutdown;
521+
518522
/*
519523
* Sleep at least 1 second after any error. We don't want to be
520524
* filling the error logs as fast as we can.
@@ -549,10 +553,14 @@ AutoVacLauncherMain(int argc, char *argv[])
549553
SetConfigOption("default_transaction_isolation", "read committed",
550554
PGC_SUSET, PGC_S_OVERRIDE);
551555

552-
/* in emergency mode, just start a worker and go away */
556+
/*
557+
* In emergency mode, just start a worker (unless shutdown was requested)
558+
* and go away.
559+
*/
553560
if (!AutoVacuumingActive())
554561
{
555-
do_start_worker();
562+
if (!got_SIGTERM)
563+
do_start_worker();
556564
proc_exit(0); /* done */
557565
}
558566

@@ -567,7 +575,8 @@ AutoVacLauncherMain(int argc, char *argv[])
567575
*/
568576
rebuild_database_list(InvalidOid);
569577

570-
for (;;)
578+
/* loop until shutdown request */
579+
while (!got_SIGTERM)
571580
{
572581
struct timeval nap;
573582
TimestampTz current_time = 0;
@@ -779,6 +788,7 @@ AutoVacLauncherMain(int argc, char *argv[])
779788
}
780789

781790
/* Normal exit from the autovac launcher is here */
791+
shutdown:
782792
ereport(LOG,
783793
(errmsg("autovacuum launcher shutting down")));
784794
AutoVacuumShmem->av_launcherpid = 0;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy