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

Commit 5df64f2

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 e4f1e0d commit 5df64f2

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/backend/postmaster/autovacuum.c

+13-3
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,10 @@ AutoVacLauncherMain(int argc, char *argv[])
507507
/* Now we can allow interrupts again */
508508
RESUME_INTERRUPTS();
509509

510+
/* if in shutdown mode, no need for anything further; just go away */
511+
if (got_SIGTERM)
512+
goto shutdown;
513+
510514
/*
511515
* Sleep at least 1 second after any error. We don't want to be
512516
* filling the error logs as fast as we can.
@@ -542,10 +546,14 @@ AutoVacLauncherMain(int argc, char *argv[])
542546
SetConfigOption("default_transaction_isolation", "read committed",
543547
PGC_SUSET, PGC_S_OVERRIDE);
544548

545-
/* in emergency mode, just start a worker and go away */
549+
/*
550+
* In emergency mode, just start a worker (unless shutdown was requested)
551+
* and go away.
552+
*/
546553
if (!AutoVacuumingActive())
547554
{
548-
do_start_worker();
555+
if (!got_SIGTERM)
556+
do_start_worker();
549557
proc_exit(0); /* done */
550558
}
551559

@@ -560,7 +568,8 @@ AutoVacLauncherMain(int argc, char *argv[])
560568
*/
561569
rebuild_database_list(InvalidOid);
562570

563-
for (;;)
571+
/* loop until shutdown request */
572+
while (!got_SIGTERM)
564573
{
565574
struct timeval nap;
566575
TimestampTz current_time = 0;
@@ -758,6 +767,7 @@ AutoVacLauncherMain(int argc, char *argv[])
758767
}
759768

760769
/* Normal exit from the autovac launcher is here */
770+
shutdown:
761771
ereport(LOG,
762772
(errmsg("autovacuum launcher shutting down")));
763773
AutoVacuumShmem->av_launcherpid = 0;

0 commit comments

Comments
 (0)