*** a/src/backend/replication/walsender.c
--- b/src/backend/replication/walsender.c
***************
*** 394,401 **** WalSndLoop(void)
  		 */
  		if (ready_to_stop)
  		{
! 			XLogSend(&output_message, &caughtup);
! 			shutdown_requested = true;
  		}
  
  		/* Normal exit from the walsender is here */
--- 394,403 ----
  		 */
  		if (ready_to_stop)
  		{
! 			if (!XLogSend(&output_message, &caughtup))
! 				goto eof;
! 			if (caughtup)
! 				shutdown_requested = true;
  		}
  
  		/* Normal exit from the walsender is here */
***************
*** 458,464 **** eof:
  static void
  InitWalSnd(void)
  {
- 	/* use volatile pointer to prevent code rearrangement */
  	int			i;
  
  	/*
--- 460,465 ----
***************
*** 474,479 **** InitWalSnd(void)
--- 475,481 ----
  	 */
  	for (i = 0; i < max_wal_senders; i++)
  	{
+ 		/* use volatile pointer to prevent code rearrangement */
  		volatile WalSnd *walsnd = &WalSndCtl->walsnds[i];
  
  		SpinLockAcquire(&walsnd->mutex);
