Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 5fd56b9

Browse files
committed
Again report a useful error message when walreceiver's connection closes.
Since 7c4f524 (merged in v10), a shutdown master is reported as FATAL: unexpected result after CommandComplete: server closed the connection unexpectedly by walsender. It used to be LOG: replication terminated by primary server FATAL: could not send end-of-streaming message to primary: no COPY in progress while the old message clearly is not perfect, it's definitely better than what's reported now. The change comes from the attempt to handle finished COPYs without erroring out, needed for the new logical replication, which wasn't needed before. There's probably better ways to handle this, but for now just explicitly check for a closed connection. Author: Petr Jelinek Reviewed-By: Andres Freund Discussion: https://postgr.es/m/f7c7dd08-855c-e4ed-41f4-d064a6c0665a@2ndquadrant.com Backpatch: -
1 parent 5c4109f commit 5fd56b9

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/backend/replication/libpqwalreceiver/libpqwalreceiver.c

+14-1
Original file line numberDiff line numberDiff line change
@@ -682,12 +682,25 @@ libpqrcv_receive(WalReceiverConn *conn, char **buffer,
682682
{
683683
PQclear(res);
684684

685-
/* Verify that there are no more results */
685+
/* Verify that there are no more results. */
686686
res = PQgetResult(conn->streamConn);
687687
if (res != NULL)
688+
{
689+
PQclear(res);
690+
691+
/*
692+
* If the other side closed the connection orderly (otherwise
693+
* we'd seen an error, or PGRES_COPY_IN) don't report an error
694+
* here, but let callers deal with it.
695+
*/
696+
if (PQstatus(conn->streamConn) == CONNECTION_BAD)
697+
return -1;
698+
688699
ereport(ERROR,
689700
(errmsg("unexpected result after CommandComplete: %s",
690701
PQerrorMessage(conn->streamConn))));
702+
}
703+
691704
return -1;
692705
}
693706
else if (PQresultStatus(res) == PGRES_COPY_IN)

0 commit comments

Comments
 (0)