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

Commit b53942e

Browse files
committed
Ensure libpq reports a suitable error message on unexpected socket EOF.
The EOF-detection logic in pqReadData was a bit confused about who should set up the error message in case the kernel gives us read-ready-but-no-data rather than ECONNRESET or some other explicit error condition. Since the whole point of this situation is that the lower-level functions don't know there's anything wrong, pqReadData itself must set up the message. But keep the assumption that if an errno was reported, a message was set up at lower levels. Per bug #11712 from Marko Tiikkaja. It's been like this for a very long time, so back-patch to all supported branches.
1 parent 2f51f42 commit b53942e

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

src/interfaces/libpq/fe-misc.c

+11-8
Original file line numberDiff line numberDiff line change
@@ -763,12 +763,8 @@ pqReadData(PGconn *conn)
763763
/* ready for read */
764764
break;
765765
default:
766-
printfPQExpBuffer(&conn->errorMessage,
767-
libpq_gettext(
768-
"server closed the connection unexpectedly\n"
769-
"\tThis probably means the server terminated abnormally\n"
770-
"\tbefore or while processing the request.\n"));
771-
goto definitelyFailed;
766+
/* we override pqReadReady's message with something more useful */
767+
goto definitelyEOF;
772768
}
773769

774770
/*
@@ -807,9 +803,16 @@ pqReadData(PGconn *conn)
807803

808804
/*
809805
* OK, we are getting a zero read even though select() says ready. This
810-
* means the connection has been closed. Cope. Note that errorMessage
811-
* has been set already.
806+
* means the connection has been closed. Cope.
812807
*/
808+
definitelyEOF:
809+
printfPQExpBuffer(&conn->errorMessage,
810+
libpq_gettext(
811+
"server closed the connection unexpectedly\n"
812+
"\tThis probably means the server terminated abnormally\n"
813+
"\tbefore or while processing the request.\n"));
814+
815+
/* Come here if lower-level code already set a suitable errorMessage */
813816
definitelyFailed:
814817
pqDropConnection(conn);
815818
conn->status = CONNECTION_BAD; /* No more connection to backend */

0 commit comments

Comments
 (0)