*** a/src/backend/replication/walsender.c
--- b/src/backend/replication/walsender.c
***************
*** 286,299 **** WalSndHandshake(void)
  				break;
  			}
  
! 			/* 'X' means that the standby is closing the connection */
  			case 'X':
- 				proc_exit(0);
- 
  			case EOF:
! 				ereport(ERROR,
! 						(errcode(ERRCODE_PROTOCOL_VIOLATION),
! 						 errmsg("unexpected EOF on standby connection")));
  
  			default:
  				ereport(FATAL,
--- 286,299 ----
  				break;
  			}
  
! 			/*
! 			 * 'X' means that the standby is closing the connection. EOF
! 			 * means unexpected loss of standby connection. Either way,
! 			 * perform normal shutdown.
! 			 */
  			case 'X':
  			case EOF:
! 				proc_exit(0);
  
  			default:
  				ereport(FATAL,
***************
*** 309,318 **** WalSndHandshake(void)
  static void
  CheckClosedConnection(void)
  {
! 	unsigned char firstchar;
  	int r;
  
! 	r = pq_getbyte_if_available(&firstchar);
  	if (r < 0)
  	{
  		/* no data available */
--- 309,318 ----
  static void
  CheckClosedConnection(void)
  {
! 	int firstchar;
  	int r;
  
! 	r = pq_getbyte_if_available((unsigned char *) &firstchar);
  	if (r < 0)
  	{
  		/* no data available */
***************
*** 328,341 **** CheckClosedConnection(void)
  
  		ereport(COMMERROR,
  				(errcode_for_socket_access(),
! 				 errmsg("could not receive data from client: %m")));
  	}
  	if (r == 0)
  	{
  		/* standby disconnected unexpectedly */
! 		ereport(ERROR,
! 				(errcode(ERRCODE_PROTOCOL_VIOLATION),
! 				 errmsg("unexpected EOF on standby connection")));
  	}
  
  	/* Handle the very limited subset of commands expected in this phase */
--- 328,340 ----
  
  		ereport(COMMERROR,
  				(errcode_for_socket_access(),
! 				 errmsg("could not receive data from standby: %m")));
! 		firstchar = EOF;
  	}
  	if (r == 0)
  	{
  		/* standby disconnected unexpectedly */
! 		firstchar = EOF;
  	}
  
  	/* Handle the very limited subset of commands expected in this phase */
***************
*** 346,351 **** CheckClosedConnection(void)
--- 345,354 ----
  		 * unexpected loss of standby connection. Either way, perform normal
  		 * shutdown.
  		 */
+ 		case EOF:
+ 			ereport(COMMERROR,
+ 					(errcode(ERRCODE_PROTOCOL_VIOLATION),
+ 					 errmsg("unexpected EOF on standby connection")));
  		case 'X':
  			proc_exit(0);
  
