Skip to content

Commit 6fa31d8

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 fd29810 commit 6fa31d8

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
@@ -764,12 +764,8 @@ pqReadData(PGconn *conn)
764764
/* ready for read */
765765
break;
766766
default:
767-
printfPQExpBuffer(&conn->errorMessage,
768-
libpq_gettext(
769-
"server closed the connection unexpectedly\n"
770-
"\tThis probably means the server terminated abnormally\n"
771-
"\tbefore or while processing the request.\n"));
772-
goto definitelyFailed;
767+
/* we override pqReadReady's message with something more useful */
768+
goto definitelyEOF;
773769
}
774770

775771
/*
@@ -808,9 +804,16 @@ pqReadData(PGconn *conn)
808804

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

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy