Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1deP9L-0008It-GE for pgsql-bugs@arkaria.postgresql.org; Sun, 06 Aug 2017 17:15:35 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1deP9K-00037O-T7 for pgsql-bugs@arkaria.postgresql.org; Sun, 06 Aug 2017 17:15:34 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1deP8Z-0001jI-W3 for pgsql-bugs@postgresql.org; Sun, 06 Aug 2017 17:14:48 +0000 Received: from out1-smtp.messagingengine.com ([66.111.4.25]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1deP8S-0003ax-6s for pgsql-bugs@postgresql.org; Sun, 06 Aug 2017 17:14:46 +0000 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id 8618A20B14; Sun, 6 Aug 2017 13:14:38 -0400 (EDT) Received: from frontend2 ([10.202.2.161]) by compute5.internal (MEProxy); Sun, 06 Aug 2017 13:14:38 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-sender :x-me-sender:x-sasl-enc:x-sasl-enc; s=fm1; bh=Y10QXTRZ2SMXC/BO3m 9mt9MHPGutpNdnlm/m5r09TCg=; b=W/Hl9rsdTf+6JSWWv3TkMrIVQSDADGBYig WzlkTP3PWzz0bLLYqVcgJPzcz356Rd2poP2lX0WpZ1I+XrEWcjAtu2WNwlmYs1Ql rJI9y3Fp6FAn7IeMz75d9M+K0e+QQOZ0h7CTMbHFb0EyOk/TfgrqZMlxaWTSYZhF nf4XxsPYeO+QQGfnPRhPof4lTwJvycsQeFBj9qEaVeeJt5V98B78iuDuRjVLxLES gLkRdK0z8Oz9VnQn6Gc6vHYj4M5OBS0sgWFp/bPP6YjugwAu3fvcxTYxeAXVsq1H YO1KNAPs4iA6g/7pV48pj9YWWAfpT1VeOXMVWCB9wdYrRO/UOWkA== X-ME-Sender: X-Sasl-enc: 5yzTAzOC8ehoODYi1dvvAsoFhubQJxCJ339I8t8juUqx 1502039678 Received: from intern.anarazel.de (unknown [136.24.76.72]) by mail.messagingengine.com (Postfix) with ESMTPA id 38B72245AD; Sun, 6 Aug 2017 13:14:38 -0400 (EDT) Date: Sun, 6 Aug 2017 10:14:36 -0700 From: Andres Freund To: Tom Lane Cc: Noah Misch , "Augustine, Jobin" , pgsql-bugs@postgresql.org Subject: Re: Replication to Postgres 10 on Windows is broken Message-ID: <20170806171436.ve646fu4bpagdrc2@alap3.anarazel.de> References: <20170806062634.GA3180536@rfd.leadboat.com> <3819.1502032677@sss.pgh.pa.us> <20170806155037.GD3179882@rfd.leadboat.com> <6525.1502036947@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <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 Hi, On 2017-08-06 12:29:07 -0400, Tom Lane wrote: > 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=vs.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=vs.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. Nice digging. > 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? I'm a bit hesitant to do so at this phase of the release cycle, it'd kind of force all users to upgrade their code, and I'm sure there's a couple out-of-tree ones. And not just code explicitly using new versions of libpq, also users of old versions - several distributions just install newer libpq versions and rely on it being compatible. > If not, can we tell in > WaitEventAdjustWin32 that the socket is still connecting and we must > substitute FD_CONNECT for FD_WRITE? I was wondering, for a second, if we should just always use FD_CONNECT once in every set. But unfortunately there's plenty places that create/destroy sets at a high enough speed for that to not be a nice solution. A third solution would be to, for v10, add a #ifdef WIN32 block to libpqrcv_connect() that just waits till FD_CONNECT is ready. That has the disadvantage of not accepting interrupts, but still seems better than not working at all. That's not much of a real solution, but this late in the cycle it might be advisable to hold our noses :( Greetings, Andres Freund -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs