*** a/src/backend/commands/copy.c
--- b/src/backend/commands/copy.c
***************
*** 547,553 **** CopyGetData(CopyState cstate, void *databuf, int minread, int maxread)
  				/* Only a \. terminator is legal EOF in old protocol */
  				ereport(ERROR,
  						(errcode(ERRCODE_CONNECTION_FAILURE),
! 						 errmsg("unexpected EOF on client connection")));
  			}
  			bytesread = minread;
  			break;
--- 547,553 ----
  				/* Only a \. terminator is legal EOF in old protocol */
  				ereport(ERROR,
  						(errcode(ERRCODE_CONNECTION_FAILURE),
! 						 errmsg("unexpected EOF on client connection with an open transaction")));
  			}
  			bytesread = minread;
  			break;
***************
*** 566,576 **** CopyGetData(CopyState cstate, void *databuf, int minread, int maxread)
  					if (mtype == EOF)
  						ereport(ERROR,
  								(errcode(ERRCODE_CONNECTION_FAILURE),
! 							 errmsg("unexpected EOF on client connection")));
  					if (pq_getmessage(cstate->fe_msgbuf, 0))
  						ereport(ERROR,
  								(errcode(ERRCODE_CONNECTION_FAILURE),
! 							 errmsg("unexpected EOF on client connection")));
  					switch (mtype)
  					{
  						case 'd':		/* CopyData */
--- 566,576 ----
  					if (mtype == EOF)
  						ereport(ERROR,
  								(errcode(ERRCODE_CONNECTION_FAILURE),
! 							 errmsg("unexpected EOF on client connection with an open transaction")));
  					if (pq_getmessage(cstate->fe_msgbuf, 0))
  						ereport(ERROR,
  								(errcode(ERRCODE_CONNECTION_FAILURE),
! 							 errmsg("unexpected EOF on client connection with an open transaction")));
  					switch (mtype)
  					{
  						case 'd':		/* CopyData */
*** a/src/backend/tcop/fastpath.c
--- b/src/backend/tcop/fastpath.c
***************
*** 285,293 **** HandleFunctionRequest(StringInfo msgBuf)
  	{
  		if (GetOldFunctionMessage(msgBuf))
  		{
! 			ereport(COMMERROR,
! 					(errcode(ERRCODE_PROTOCOL_VIOLATION),
! 					 errmsg("unexpected EOF on client connection")));
  			return EOF;
  		}
  	}
--- 285,304 ----
  	{
  		if (GetOldFunctionMessage(msgBuf))
  		{
! 			if (IsTransactionState())
! 				ereport(COMMERROR,
! 						(errcode(ERRCODE_CONNECTION_FAILURE),
! 						 errmsg("unexpected EOF on client connection with an open transaction")));
! 			else
! 			{
! 				/* Can't send DEBUG log messages to client at this point */
! 				CommandDest savedest = whereToSendOutput;
! 				whereToSendOutput = DestNone;
! 				ereport(DEBUG1,
! 						(errcode(ERRCODE_CONNECTION_DOES_NOT_EXIST),
! 						 errmsg("unexpected EOF on client connection")));
! 				whereToSendOutput = savedest;
! 			}
  			return EOF;
  		}
  	}
*** a/src/backend/tcop/postgres.c
--- b/src/backend/tcop/postgres.c
***************
*** 343,351 **** SocketBackend(StringInfo inBuf)
  
  	if (qtype == EOF)			/* frontend disconnected */
  	{
! 		ereport(COMMERROR,
! 				(errcode(ERRCODE_PROTOCOL_VIOLATION),
! 				 errmsg("unexpected EOF on client connection")));
  		return qtype;
  	}
  
--- 343,362 ----
  
  	if (qtype == EOF)			/* frontend disconnected */
  	{
! 		if (IsTransactionState())
! 			ereport(COMMERROR,
! 					(errcode(ERRCODE_CONNECTION_FAILURE),
! 					 errmsg("unexpected EOF on client connection with an open transaction")));
! 		else
! 		{
! 			/* Can't send DEBUG log messages to client at this point */
! 			CommandDest savedest = whereToSendOutput;
! 			whereToSendOutput = DestNone;
! 			ereport(DEBUG1,
! 					(errcode(ERRCODE_CONNECTION_DOES_NOT_EXIST),
! 					 errmsg("unexpected EOF on client connection")));
! 			whereToSendOutput = savedest;
! 		}
  		return qtype;
  	}
  
***************
*** 366,374 **** SocketBackend(StringInfo inBuf)
  				/* old style without length word; convert */
  				if (pq_getstring(inBuf))
  				{
! 					ereport(COMMERROR,
! 							(errcode(ERRCODE_PROTOCOL_VIOLATION),
! 							 errmsg("unexpected EOF on client connection")));
  					return EOF;
  				}
  			}
--- 377,396 ----
  				/* old style without length word; convert */
  				if (pq_getstring(inBuf))
  				{
! 					if (IsTransactionState())
! 						ereport(COMMERROR,
! 								(errcode(ERRCODE_CONNECTION_FAILURE),
! 								 errmsg("unexpected EOF on client connection with an open transaction")));
! 					else
! 					{
! 						/* Can't send DEBUG log messages to client at this point */
! 						CommandDest savedest = whereToSendOutput;
! 						whereToSendOutput = DestNone;
! 						ereport(DEBUG1,
! 								(errcode(ERRCODE_CONNECTION_DOES_NOT_EXIST),
! 								 errmsg("unexpected EOF on client connection")));
! 						whereToSendOutput = savedest;
! 					}
  					return EOF;
  				}
  			}
