8000 Ensure libpq reports a suitable error message on unexpected socket EOF. · leelingco/postgres@9814437 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9814437

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 d5fef87 commit 9814437

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

src/interfaces/libpq/fe-misc.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -738,12 +738,8 @@ pqReadData(PGconn *conn)
738738
/* ready for read */
739739
break;
740740
default:
741-
printfPQExpBuffer(&conn->errorMessage,
742-
libpq_gettext(
743-
"server closed the connection unexpectedly\n"
744-
"\tThis probably means the server terminated abnormally\n"
745-
"\tbefore or while processing the request.\n"));
746-
goto definitelyFailed;
741+
/* we override pqReadReady's message with something more useful */
742+
goto definitelyEOF;
747743
}
748744

749745
/*
@@ -782,9 +778,16 @@ pqReadData(PGconn *conn)
782778

783779
/*
784780
* OK, we are getting a zero read even though select() says ready. This
785-
* means the connection has been closed. Cope. Note that errorMessage
786-
* has been set already.
781+
* means the connection has been closed. Cope.
787782
*/
783+
definitelyEOF:
784+
printfPQExpBuffer(&conn->errorMessage,
785+
libpq_gettext(
786+
"server closed the connection unexpectedly\n"
787+
"\tThis probably means the server terminated abnormally\n"
788+
"\tbefore or while processing the request.\n"));
789+
790+
/* Come here if lower-level code already set a suitable errorMessage */
788791
definitelyFailed:
789792
conn->status = CONNECTION_BAD; /* No more connection to backend */
790793
pqsecure_close(conn);

0 commit comments

Comments
 (0)
0