diff --git a/src/interfaces/libpq/fe-exec.c b/src/interfaces/libpq/fe-exec.c index 3a8cddf4ff4..b603ecfe7c7 100644 --- a/src/interfaces/libpq/fe-exec.c +++ b/src/interfaces/libpq/fe-exec.c @@ -1761,10 +1761,14 @@ PQisBusy(PGconn *conn) parseInput(conn); /* - * PQgetResult will return immediately in all states except BUSY, or if we - * had a write failure. + * PQgetResult will return immediately in all states except BUSY. Also, + * if we've detected read EOF and dropped the connection, we can expect + * that PQgetResult will fail immediately. Note that we do *not* check + * conn->write_failed here --- once that's become set, we know we have + * trouble, but we need to keep trying to read until we have a complete + * server message or detect read EOF. */ - return conn->asyncStatus == PGASYNC_BUSY || conn->write_failed; + return conn->asyncStatus == PGASYNC_BUSY && conn->status != CONNECTION_BAD; } diff --git a/src/interfaces/libpq/fe-secure-openssl.c b/src/interfaces/libpq/fe-secure-openssl.c index 663439c251a..80faceefa23 100644 --- a/src/interfaces/libpq/fe-secure-openssl.c +++ b/src/interfaces/libpq/fe-secure-openssl.c @@ -1496,7 +1496,7 @@ my_sock_write(BIO *h, const char *buf, int size) res = pqsecure_raw_write((PGconn *) BIO_get_data(h), buf, size); BIO_clear_retry_flags(h); - if (res <= 0) + if (res < 0) { /* If we were interrupted, tell caller to retry */ switch (SOCK_ERRNO)