Skip to content

Commit e434ad3

Browse files
committed
Reorder the asynchronous libpq calls for replication connection
Per libpq documentation, the initial state must be PGRES_POLLING_WRITING. Failing to do that appears to cause some issues on some Windows systems. From: Petr Jelinek <petr.jelinek@2ndquadrant.com>
1 parent 6f3a13f commit e434ad3

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

src/backend/replication/libpqwalreceiver/libpqwalreceiver.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -155,12 +155,16 @@ libpqrcv_connect(const char *conninfo, bool logical, const char *appname,
155155
return NULL;
156156
}
157157

158-
/* Poll connection. */
159-
do
158+
/*
159+
* Poll connection until we have OK or FAILED status.
160+
*
161+
* Note that the initial state after PQconnectStartParams is
162+
* PGRES_POLLING_WRITING.
163+
*/
164+
for (status = PGRES_POLLING_WRITING;
165+
status != PGRES_POLLING_OK && status != PGRES_POLLING_FAILED;
166+
status = PQconnectPoll(conn->streamConn))
160167
{
161-
/* Determine current state of the connection. */
162-
status = PQconnectPoll(conn->streamConn);
163-
164168
/* Sleep a bit if waiting for socket. */
165169
if (status == PGRES_POLLING_READING ||
166170
status == PGRES_POLLING_WRITING)
@@ -188,9 +192,7 @@ libpqrcv_connect(const char *conninfo, bool logical, const char *appname,
188192
if (rc & WL_LATCH_SET)
189193
CHECK_FOR_INTERRUPTS();
190194
}
191-
192-
/* Otherwise loop until we have OK or FAILED status. */
193-
} while (status != PGRES_POLLING_OK && status != PGRES_POLLING_FAILED);
195+
}
194196

195197
if (PQstatus(conn->streamConn) != CONNECTION_OK)
196198
{

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