From f04db050a583c9c01eb77766f830a0cf77b0a6c7 Mon Sep 17 00:00:00 2001 From: Vignesh C Date: Mon, 5 Feb 2024 14:55:48 +0530 Subject: [PATCH v5 2/2] Apply worker will get started after 180 seconds by the launcher in case the apply worker exits immediately after startup. Apply worker was getting started after 180 seconds tiemout of the launcher in case the apply worker exits immediately after startup. This was happening because the launcher process's latch was getting reset after the apply worker was started, which resulted in the launcher to wait for the next 180 seconds timeout before starting the apply worker. Fixed this issue by not resetting the latch, as this latch will be set for subscription modifications and apply worker exit. We should check if the new worker needs to be started or not and reset the latch in ApplyLauncherMain. --- src/backend/replication/logical/launcher.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/backend/replication/logical/launcher.c b/src/backend/replication/logical/launcher.c index 122db0bb13..a754f2c757 100644 --- a/src/backend/replication/logical/launcher.c +++ b/src/backend/replication/logical/launcher.c @@ -191,7 +191,6 @@ WaitForReplicationWorkerAttach(LogicalRepWorker *worker, BackgroundWorkerHandle *handle) { BgwHandleStatus status; - int rc; for (;;) { @@ -226,16 +225,14 @@ WaitForReplicationWorkerAttach(LogicalRepWorker *worker, /* * We need timeout because we generally don't get notified via latch * about the worker attach. But we don't expect to have to wait long. + * Since this latch is also used for subscription creation/modification + * and apply worker process exit signal handling, the latch must not be + * reset here. We should check if the new worker needs to be started or + * not and reset the latch in ApplyLauncherMain. */ - rc = WaitLatch(MyLatch, - WL_LATCH_SET | WL_TIMEOUT | WL_EXIT_ON_PM_DEATH, - 10L, WAIT_EVENT_BGWORKER_STARTUP); - - if (rc & WL_LATCH_SET) - { - ResetLatch(MyLatch); - CHECK_FOR_INTERRUPTS(); - } + (void) WaitLatch(MyLatch, + WL_TIMEOUT | WL_EXIT_ON_PM_DEATH, + 10L, WAIT_EVENT_BGWORKER_STARTUP); } } -- 2.34.1