Skip to content

Commit c6fda5a

Browse files
committed
Eliminate one background-worker-related flag variable.
Teach sigusr1_handler() to use the same test for whether a worker might need to be started as ServerLoop(). Aside from being perhaps a bit simpler, this prevents a potentially-unbounded delay when starting a background worker. On some platforms, select() doesn't return when interrupted by a signal, but is instead restarted, including a reset of the timeout to the originally-requested value. If signals arrive often enough, but no connection requests arrive, sigusr1_handler() will be executed repeatedly, but the body of ServerLoop() won't be reached. This change ensures that, even in that case, background workers will eventually get launched. This is far from a perfect fix; really, we need select() to return control to ServerLoop() after an interrupt, either via the self-pipe trick or some other mechanism. But that's going to require more work and discussion, so let's do this for now to at least mitigate the damage. Per investigation of test_shm_mq failures on buildfarm member anole.
1 parent bb7c8f9 commit c6fda5a

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

src/backend/postmaster/postmaster.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4757,15 +4757,14 @@ static void
47574757
sigusr1_handler(SIGNAL_ARGS)
47584758
{
47594759
int save_errno = errno;
4760-
bool start_bgworker = false;
47614760

47624761
PG_SETMASK(&BlockSig);
47634762

47644763
/* Process background worker state change. */
47654764
if (CheckPostmasterSignal(PMSIGNAL_BACKGROUND_WORKER_CHANGE))
47664765
{
47674766
BackgroundWorkerStateChange();
4768-
start_bgworker = true;
4767+
StartWorkerNeeded = true;
47694768
}
47704769

47714770
/*
@@ -4806,10 +4805,10 @@ sigusr1_handler(SIGNAL_ARGS)
48064805

48074806
pmState = PM_HOT_STANDBY;
48084807
/* Some workers may be scheduled to start now */
4809-
start_bgworker = true;
4808+
StartWorkerNeeded = true;
48104809
}
48114810

4812-
if (start_bgworker)
4811+
if (StartWorkerNeeded || HaveCrashedWorker)
48134812
maybe_start_bgworker();
48144813

48154814
if (CheckPostmasterSignal(PMSIGNAL_WAKEN_ARCHIVER) &&

0 commit comments

Comments
 (0)