Commit 1de0a4e0 authored by Robert Haas's avatar Robert Haas

libpq: Make target_session_attrs=read-write consume empty result.

Otherwise, the leftover empty result can cause problems in some
situations.

Michael Paquier and Ashutosh Bapat, per a report from Higuchi Daisuke
parent fbe7a3fa
...@@ -1896,6 +1896,7 @@ PQconnectPoll(PGconn *conn) ...@@ -1896,6 +1896,7 @@ PQconnectPoll(PGconn *conn)
case CONNECTION_SSL_STARTUP: case CONNECTION_SSL_STARTUP:
case CONNECTION_NEEDED: case CONNECTION_NEEDED:
case CONNECTION_CHECK_WRITABLE: case CONNECTION_CHECK_WRITABLE:
case CONNECTION_CONSUME:
break; break;
default: default:
...@@ -2935,6 +2936,34 @@ keep_going: /* We will come back to here until there is ...@@ -2935,6 +2936,34 @@ keep_going: /* We will come back to here until there is
conn->status = CONNECTION_OK; conn->status = CONNECTION_OK;
return PGRES_POLLING_OK; return PGRES_POLLING_OK;
case CONNECTION_CONSUME:
{
conn->status = CONNECTION_OK;
if (!PQconsumeInput(conn))
goto error_return;
if (PQisBusy(conn))
{
conn->status = CONNECTION_CONSUME;
restoreErrorMessage(conn, &savedMessage);
return PGRES_POLLING_READING;
}
/*
* Call PQgetResult() again to consume NULL result.
*/
res = PQgetResult(conn);
if (res != NULL)
{
PQclear(res);
conn->status = CONNECTION_CONSUME;
goto keep_going;
}
/* We are open for business! */
conn->status = CONNECTION_OK;
return PGRES_POLLING_OK;
}
case CONNECTION_CHECK_WRITABLE: case CONNECTION_CHECK_WRITABLE:
{ {
if (!saveErrorMessage(conn, &savedMessage)) if (!saveErrorMessage(conn, &savedMessage))
...@@ -2994,9 +3023,12 @@ keep_going: /* We will come back to here until there is ...@@ -2994,9 +3023,12 @@ keep_going: /* We will come back to here until there is
/* We can release the address lists now. */ /* We can release the address lists now. */
release_all_addrinfo(conn); release_all_addrinfo(conn);
/* We are open for business! */ /*
conn->status = CONNECTION_OK; * Finish reading any remaining messages before
return PGRES_POLLING_OK; * being considered as ready.
*/
conn->status = CONNECTION_CONSUME;
goto keep_going;
} }
/* /*
......
...@@ -63,8 +63,10 @@ typedef enum ...@@ -63,8 +63,10 @@ typedef enum
CONNECTION_SETENV, /* Negotiating environment. */ CONNECTION_SETENV, /* Negotiating environment. */
CONNECTION_SSL_STARTUP, /* Negotiating SSL. */ CONNECTION_SSL_STARTUP, /* Negotiating SSL. */
CONNECTION_NEEDED, /* Internal state: connect() needed */ CONNECTION_NEEDED, /* Internal state: connect() needed */
CONNECTION_CHECK_WRITABLE /* Check if we could make a writable CONNECTION_CHECK_WRITABLE, /* Check if we could make a writable
* connection. */ * connection. */
CONNECTION_CONSUME /* Wait for any pending message and
* consume them. */
} ConnStatusType; } ConnStatusType;
typedef enum typedef enum
......
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