]> granicus.if.org Git - postgresql/commitdiff
Reorder the asynchronous libpq calls for replication connection
authorPeter Eisentraut <peter_e@gmx.net>
Mon, 6 Mar 2017 14:33:26 +0000 (09:33 -0500)
committerPeter Eisentraut <peter_e@gmx.net>
Mon, 6 Mar 2017 14:33:26 +0000 (09:33 -0500)
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>

src/backend/replication/libpqwalreceiver/libpqwalreceiver.c

index 048d2aaa76b8cca5bfd02d2487f5827c2879301a..ebadf3680f62708fcdf4abe71d092d6c48a97e35 100644 (file)
@@ -155,12 +155,16 @@ libpqrcv_connect(const char *conninfo, bool logical, const char *appname,
                return NULL;
        }
 
-       /* Poll connection. */
-       do
+       /*
+        * Poll connection until we have OK or FAILED status.
+        *
+        * Note that the initial state after PQconnectStartParams is
+        * PGRES_POLLING_WRITING.
+        */
+       for (status = PGRES_POLLING_WRITING;
+                status != PGRES_POLLING_OK && status != PGRES_POLLING_FAILED;
+                status = PQconnectPoll(conn->streamConn))
        {
-               /* Determine current state of the connection. */
-               status = PQconnectPoll(conn->streamConn);
-
                /* Sleep a bit if waiting for socket. */
                if (status == PGRES_POLLING_READING ||
                        status == PGRES_POLLING_WRITING)
@@ -188,9 +192,7 @@ libpqrcv_connect(const char *conninfo, bool logical, const char *appname,
                        if (rc & WL_LATCH_SET)
                                CHECK_FOR_INTERRUPTS();
                }
-
-               /* Otherwise loop until we have OK or FAILED status. */
-       } while (status != PGRES_POLLING_OK && status != PGRES_POLLING_FAILED);
+       }
 
        if (PQstatus(conn->streamConn) != CONNECTION_OK)
        {