Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1deORN-0006U0-2T for pgsql-bugs@arkaria.postgresql.org; Sun, 06 Aug 2017 16:30:09 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1deORL-00086W-0F for pgsql-bugs@arkaria.postgresql.org; Sun, 06 Aug 2017 16:30:07 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1deOQe-0006qo-3G for pgsql-bugs@postgresql.org; Sun, 06 Aug 2017 16:29:24 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1deOQW-0004gW-3N for pgsql-bugs@postgresql.org; Sun, 06 Aug 2017 16:29:23 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id v76GT7vI006526; Sun, 6 Aug 2017 12:29:07 -0400 From: Tom Lane To: Noah Misch cc: "Augustine, Jobin" , pgsql-bugs@postgresql.org, Andres Freund Subject: Re: Replication to Postgres 10 on Windows is broken In-reply-to: <20170806155037.GD3179882@rfd.leadboat.com> References: <20170806062634.GA3180536@rfd.leadboat.com> <3819.1502032677@sss.pgh.pa.us> <20170806155037.GD3179882@rfd.leadboat.com> Comments: In-reply-to Noah Misch message dated "Sun, 06 Aug 2017 08:50:37 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <6524.1502036947.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Sun, 06 Aug 2017 12:29:07 -0400 Message-ID: <6525.1502036947@sss.pgh.pa.us> List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org Noah Misch writes: > On Sun, Aug 06, 2017 at 11:17:57AM -0400, Tom Lane wrote: >> Gut instinct says that the reason this case fails when other tools >> can connect successfully is that libpqwalreceiver is the only tool >> that uses PQconnectStart/PQconnectPoll rather than a plain >> PQconnectdb, and that there is some behavioral difference between >> connectDBComplete's wait loop and libpqrcv_connect's wait loop that > That would fit. Until v10 (commit 1e8a850), PQconnectStart() had no in-t= ree > callers outside of libpq itself. Yeah. After some digging around I think I see exactly what is happening. The error message would be better read as "Socket is not connected *yet*", that is, the problem is that we're trying to write data before the nonblocking connection request has completed. (This fits with the OP's observation that local loopback connections work fine --- they probably complete immediately.) PQconnectPoll believes that it just has to wait for write-ready when waiting for a connection to complete. When using connectDBComplete's wait loop, that reduces to a call to Windows' version of select(2), in pqSocketPoll, and according to https://msdn.microsoft.com/en-us/library/windows/desktop/ms740141(v=3Dvs.85= ).aspx "The parameter writefds identifies the sockets that are to be checked for writability. If a socket is processing a connect call (nonblocking), a socket is writeable if the connection establishment successfully completes." On the other hand, in libpqwalreceiver, we're depending on latch.c's implementation, and it uses WSAEventSelect's FD_WRITE event: https://msdn.microsoft.com/en-us/library/windows/desktop/ms741576(v=3Dvs.85= ).aspx If I'm reading that correctly, FD_WRITE is set instantly by the connect request, probably even in the nonblock case, and it only gets cleared by a failed write request. It looks to me like we would have to specifically look for FD_CONNECT, *not* FD_WRITE, to make this work. This is problematic, because the APIs in between don't provide a way to report that we're still waiting for connect rather than for data-write-ready. Anybody have the stomach for extending PQconnectPoll's API with an extra PGRES_POLLING_CONNECTING state? If not, can we tell in WaitEventAdjustWin32 that the socket is still connecting and we must substitute FD_CONNECT for FD_WRITE? regards, tom lane --=20 Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs