diff --git a/src/backend/replication/logical/launcher.c b/src/backend/replication/logical/launcher.c
index 961110c..d165d51 100644
*** a/src/backend/replication/logical/launcher.c
--- b/src/backend/replication/logical/launcher.c
*************** WaitForReplicationWorkerAttach(LogicalRe
*** 201,211 ****
  
  		/*
  		 * We need timeout because we generally don't get notified via latch
! 		 * about the worker attach.
  		 */
  		rc = WaitLatch(MyLatch,
  					   WL_LATCH_SET | WL_TIMEOUT | WL_POSTMASTER_DEATH,
! 					   1000L, WAIT_EVENT_BGWORKER_STARTUP);
  
  		/* emergency bailout if postmaster has died */
  		if (rc & WL_POSTMASTER_DEATH)
--- 201,211 ----
  
  		/*
  		 * 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.
  		 */
  		rc = WaitLatch(MyLatch,
  					   WL_LATCH_SET | WL_TIMEOUT | WL_POSTMASTER_DEATH,
! 					   10L, WAIT_EVENT_BGWORKER_STARTUP);
  
  		/* emergency bailout if postmaster has died */
  		if (rc & WL_POSTMASTER_DEATH)
*************** retry:
*** 408,415 ****
  }
  
  /*
!  * Stop the logical replication worker and wait until it detaches from the
!  * slot.
   */
  void
  logicalrep_worker_stop(Oid subid, Oid relid)
--- 408,415 ----
  }
  
  /*
!  * Stop the logical replication worker for subid/relid, if any, and wait until
!  * it detaches from the slot.
   */
  void
  logicalrep_worker_stop(Oid subid, Oid relid)
*************** logicalrep_worker_stop(Oid subid, Oid re
*** 435,442 ****
  	generation = worker->generation;
  
  	/*
! 	 * If we found worker but it does not have proc set it is starting up,
! 	 * wait for it to finish and then kill it.
  	 */
  	while (worker->in_use && !worker->proc)
  	{
--- 435,442 ----
  	generation = worker->generation;
  
  	/*
! 	 * If we found a worker but it does not have proc set then it is still
! 	 * starting up; wait for it to finish starting and then kill it.
  	 */
  	while (worker->in_use && !worker->proc)
  	{
*************** logicalrep_worker_stop(Oid subid, Oid re
*** 444,453 ****
  
  		LWLockRelease(LogicalRepWorkerLock);
  
! 		/* Wait for signal. */
  		rc = WaitLatch(MyLatch,
  					   WL_LATCH_SET | WL_TIMEOUT | WL_POSTMASTER_DEATH,
! 					   1000L, WAIT_EVENT_BGWORKER_STARTUP);
  
  		/* emergency bailout if postmaster has died */
  		if (rc & WL_POSTMASTER_DEATH)
--- 444,453 ----
  
  		LWLockRelease(LogicalRepWorkerLock);
  
! 		/* Wait a bit --- we don't expect to have to wait long. */
  		rc = WaitLatch(MyLatch,
  					   WL_LATCH_SET | WL_TIMEOUT | WL_POSTMASTER_DEATH,
! 					   10L, WAIT_EVENT_BGWORKER_STARTUP);
  
  		/* emergency bailout if postmaster has died */
  		if (rc & WL_POSTMASTER_DEATH)
*************** logicalrep_worker_stop(Oid subid, Oid re
*** 459,465 ****
  			CHECK_FOR_INTERRUPTS();
  		}
  
! 		/* Check worker status. */
  		LWLockAcquire(LogicalRepWorkerLock, LW_SHARED);
  
  		/*
--- 459,465 ----
  			CHECK_FOR_INTERRUPTS();
  		}
  
! 		/* Recheck worker status. */
  		LWLockAcquire(LogicalRepWorkerLock, LW_SHARED);
  
  		/*
*************** logicalrep_worker_stop(Oid subid, Oid re
*** 480,506 ****
  
  	/* Now terminate the worker ... */
  	kill(worker->proc->pid, SIGTERM);
- 	LWLockRelease(LogicalRepWorkerLock);
  
  	/* ... and wait for it to die. */
  	for (;;)
  	{
  		int			rc;
  
! 		LWLockAcquire(LogicalRepWorkerLock, LW_SHARED);
  		if (!worker->proc || worker->generation != generation)
- 		{
- 			LWLockRelease(LogicalRepWorkerLock);
  			break;
- 		}
- 		LWLockRelease(LogicalRepWorkerLock);
  
! 		CHECK_FOR_INTERRUPTS();
  
! 		/* Wait for more work. */
  		rc = WaitLatch(MyLatch,
  					   WL_LATCH_SET | WL_TIMEOUT | WL_POSTMASTER_DEATH,
! 					   1000L, WAIT_EVENT_BGWORKER_SHUTDOWN);
  
  		/* emergency bailout if postmaster has died */
  		if (rc & WL_POSTMASTER_DEATH)
--- 480,501 ----
  
  	/* Now terminate the worker ... */
  	kill(worker->proc->pid, SIGTERM);
  
  	/* ... and wait for it to die. */
  	for (;;)
  	{
  		int			rc;
  
! 		/* is it gone? */
  		if (!worker->proc || worker->generation != generation)
  			break;
  
! 		LWLockRelease(LogicalRepWorkerLock);
  
! 		/* Wait a bit --- we don't expect to have to wait long. */
  		rc = WaitLatch(MyLatch,
  					   WL_LATCH_SET | WL_TIMEOUT | WL_POSTMASTER_DEATH,
! 					   10L, WAIT_EVENT_BGWORKER_SHUTDOWN);
  
  		/* emergency bailout if postmaster has died */
  		if (rc & WL_POSTMASTER_DEATH)
*************** logicalrep_worker_stop(Oid subid, Oid re
*** 511,517 ****
--- 506,516 ----
  			ResetLatch(MyLatch);
  			CHECK_FOR_INTERRUPTS();
  		}
+ 
+ 		LWLockAcquire(LogicalRepWorkerLock, LW_SHARED);
  	}
+ 
+ 	LWLockRelease(LogicalRepWorkerLock);
  }
  
  /*
