Hi,

When the replication connection is closed unexpectedly, walsender might emit
the following unfit messages. IOW, the loss of the connection might be wrongly
regarded as an arrival of invalid message by the walsender. This looks messy.
We should get rid of that unfit FATAL message, emit a COMMERROR message and
just call proc_exit() when the loss of the connection is found?

> [2460]: LOG:  could not receive data from client: No connection could be made 
> because the target machine actively refused it.
> [2460]: FATAL:  invalid standby closing message type 4
> [2460]: LOG:  could not send data to client: No connection could be made 
> because the target machine actively refused it.

Also the walsender wrongly tries to send the FATAL message to the standby even
though the connection has already been closed, and then gets the following LOG
message after the FATAL one. This FATAL message is suitable, but output of the
LOG message looks messy, too. We should use COMMERROR instead of FATAL and then
just call proc_exit() in order to prevent a message from being sent?

> [12586] FATAL:  unexpected EOF on standby connection
> [12586] LOG:  could not send data to client: Broken pipe

The attached patch fixes those unfit messages.

Regards,

-- 
Fujii Masao
NIPPON TELEGRAPH AND TELEPHONE CORPORATION
NTT Open Source Software Center
*** 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);
  
-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Reply via email to