From d101f1e18b82bac844bf17838ee8c8d03b599c9b Mon Sep 17 00:00:00 2001 From: usernamedt Date: Tue, 3 Nov 2020 19:43:45 +0500 Subject: [PATCH] Fix hanging zpq_read --- src/interfaces/libpq/fe-exec.c | 4 ++-- src/interfaces/libpq/fe-protocol3.c | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/interfaces/libpq/fe-exec.c b/src/interfaces/libpq/fe-exec.c index eea0237c3a5..00ccefbac0e 100644 --- a/src/interfaces/libpq/fe-exec.c +++ b/src/interfaces/libpq/fe-exec.c @@ -1810,8 +1810,8 @@ PQgetResult(PGconn *conn) * EOF indication. We expect therefore that this won't result in any * undue delay in reporting a previous write failure.) */ - if (flushResult || - pqWait(true, false, conn) || + if (flushResult || (zpq_buffered_rx(conn->zstream) == 0 && + pqWait(true, false, conn)) || pqReadData(conn) < 0) { /* diff --git a/src/interfaces/libpq/fe-protocol3.c b/src/interfaces/libpq/fe-protocol3.c index 4a38eed2c70..fc77a5a2e62 100644 --- a/src/interfaces/libpq/fe-protocol3.c +++ b/src/interfaces/libpq/fe-protocol3.c @@ -1679,7 +1679,7 @@ pqGetCopyData3(PGconn *conn, char **buffer, int async) if (async) return 0; /* Need to load more data */ - if (pqWait(true, false, conn) || + if ((zpq_buffered_rx(conn->zstream) == 0 && pqWait(true, false, conn)) || pqReadData(conn) < 0) return -2; continue; @@ -1737,7 +1737,7 @@ pqGetline3(PGconn *conn, char *s, int maxlen) while ((status = PQgetlineAsync(conn, s, maxlen - 1)) == 0) { /* need to load more data */ - if (pqWait(true, false, conn) || + if ((zpq_buffered_rx(conn->zstream) == 0 && pqWait(true, false, conn)) || pqReadData(conn) < 0) { *s = '\0'; @@ -1975,7 +1975,7 @@ pqFunctionCall3(PGconn *conn, Oid fnid, if (needInput) { /* Wait for some data to arrive (or for the channel to close) */ - if (pqWait(true, false, conn) || + if ((zpq_buffered_rx(conn->zstream) == 0 && pqWait(true, false, conn)) || pqReadData(conn) < 0) break; }