Commit c3e7c24a authored by Robert Haas's avatar Robert Haas

libpq: Notice errors a backend may have sent just before dying.

At least since the introduction of Hot Standby, the backend has
sometimes sent fatal errors even when no client query was in
progress, assuming that the client would receive it.  However,
pqHandleSendFailure was not in sync with this assumption, and
only tries to catch notices and notifies.  Add a parseInput call
to the loop there to fix.

Andres Freund suggested the fix.  Comments are by me.
Reviewed by Michael Paquier.
parent ac1d7945
...@@ -1553,8 +1553,8 @@ sendFailed: ...@@ -1553,8 +1553,8 @@ sendFailed:
/* /*
* pqHandleSendFailure: try to clean up after failure to send command. * pqHandleSendFailure: try to clean up after failure to send command.
* *
* Primarily, what we want to accomplish here is to process an async * Primarily, what we want to accomplish here is to process any messages that
* NOTICE message that the backend might have sent just before it died. * the backend might have sent just before it died.
* *
* NOTE: this routine should only be called in PGASYNC_IDLE state. * NOTE: this routine should only be called in PGASYNC_IDLE state.
*/ */
...@@ -1562,16 +1562,16 @@ void ...@@ -1562,16 +1562,16 @@ void
pqHandleSendFailure(PGconn *conn) pqHandleSendFailure(PGconn *conn)
{ {
/* /*
* Accept any available input data, ignoring errors. Note that if * Accept and parse any available input data. Note that if pqReadData
* pqReadData decides the backend has closed the channel, it will close * decides the backend has closed the channel, it will close our side of
* our side of the socket --- that's just what we want here. * the socket --- that's just what we want here.
*/ */
while (pqReadData(conn) > 0) while (pqReadData(conn) > 0)
/* loop until no more data readable */ ; parseInput(conn);
/* /*
* Parse any available input messages. Since we are in PGASYNC_IDLE * Make one attempt to parse available input messages even if we read no
* state, only NOTICE and NOTIFY messages will be eaten. * data.
*/ */
parseInput(conn); parseInput(conn);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment