Commit 69fed5b2 authored by Tom Lane's avatar Tom Lane

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.
parent 2ae7811d
...@@ -764,12 +764,8 @@ retry3: ...@@ -764,12 +764,8 @@ retry3:
/* ready for read */ /* ready for read */
break; break;
default: default:
printfPQExpBuffer(&conn->errorMessage, /* we override pqReadReady's message with something more useful */
libpq_gettext( goto definitelyEOF;
"server closed the connection unexpectedly\n"
"\tThis probably means the server terminated abnormally\n"
"\tbefore or while processing the request.\n"));
goto definitelyFailed;
} }
/* /*
...@@ -808,9 +804,16 @@ retry4: ...@@ -808,9 +804,16 @@ retry4:
/* /*
* OK, we are getting a zero read even though select() says ready. This * OK, we are getting a zero read even though select() says ready. This
* means the connection has been closed. Cope. Note that errorMessage * means the connection has been closed. Cope.
* has been set already.
*/ */
definitelyEOF:
printfPQExpBuffer(&conn->errorMessage,
libpq_gettext(
"server closed the connection unexpectedly\n"
"\tThis probably means the server terminated abnormally\n"
"\tbefore or while processing the request.\n"));
/* Come here if lower-level code already set a suitable errorMessage */
definitelyFailed: definitelyFailed:
pqDropConnection(conn); pqDropConnection(conn);
conn->status = CONNECTION_BAD; /* No more connection to backend */ conn->status = CONNECTION_BAD; /* No more connection to backend */
......
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