Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1deTWH-0001aF-CN for pgsql-bugs@arkaria.postgresql.org; Sun, 06 Aug 2017 21:55:33 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1deTWF-0005OR-V7 for pgsql-bugs@arkaria.postgresql.org; Sun, 06 Aug 2017 21:55:31 +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 1deTWF-0005Nk-0Y for pgsql-bugs@postgresql.org; Sun, 06 Aug 2017 21:55:31 +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 1deTW7-000135-Pf for pgsql-bugs@postgresql.org; Sun, 06 Aug 2017 21:55:29 +0000 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id 1551A20D25; Sun, 6 Aug 2017 17:55:23 -0400 (EDT) Received: from frontend2 ([10.202.2.161]) by compute5.internal (MEProxy); Sun, 06 Aug 2017 17:55:23 -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=6rjgqqBiED4dlcU/mm YyUV8Cy+ixZtEgofyCSx6OP1U=; b=hTZSTUz0cofy0B5Zy/L8mh5zkjzdNe+QKe 2NamE5FNjpAWgEI7siL6jDj61bhe5lZ5Dz6bxF2JaFdToiQdpov8me2VP7rGvJUK JjqODI42x68OtdDwYxyPyXKHmrRrD72bWiM5VWJ1lVQ4Phbp7Tcgt9tr6COldhv3 x6PJ2JvmVWoDkxcg9RVTJ1IFXp7AQ6yt1i1QefoRP4Ua3uFdni+yx4aiKjPod7We pKtKXGX8TO9JMx+pNJRafctzYhXkUBBsksgGdN40d4mZ2gKoNuhOBZr2ha6LYPuw uXzI7yACPPblKaH6q2RPfBvMgHnJ5f/70Mdp1CF3kt+pvEOqIEEg== X-ME-Sender: X-Sasl-enc: vqrgFLY3ccTWZKg2nfeKSs9IKMiUXQqWVhMwtDXrOamU 1502056522 Received: from intern.anarazel.de (unknown [96.72.164.235]) by mail.messagingengine.com (Postfix) with ESMTPA id 9346024515; Sun, 6 Aug 2017 17:55:22 -0400 (EDT) Date: Sun, 6 Aug 2017 14:55:21 -0700 From: Andres Freund To: Tom Lane , Petr Jelinek , Peter Eisentraut Cc: Noah Misch , "Augustine, Jobin" , pgsql-bugs@postgresql.org Subject: Re: Replication to Postgres 10 on Windows is broken Message-ID: <20170806215521.d6fq4esvx7s5ejka@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> <20170806171436.ve646fu4bpagdrc2@alap3.anarazel.de> <3826.1502040882@sss.pgh.pa.us> <20170806174822.puc4jq46rqltrtwq@alap3.anarazel.de> <20170806200742.sz6yshtq62ayrpa4@alap3.anarazel.de> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="43cqiovinm32zief" Content-Disposition: inline In-Reply-To: <20170806200742.sz6yshtq62ayrpa4@alap3.anarazel.de> 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 --43cqiovinm32zief Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On 2017-08-06 13:07:42 -0700, Andres Freund wrote: > Is anybody working on a patch like this? I can try writing one blindly, > if somebody else tests it. But if somebody natively on windows is > working on it, that's going to be more efficient. It'd be nice to have > something merged by wrap tomorrow... Here's a prototype patch implementing what Tom outlined. I've compiled it with mingw under linux, but haven't run it. Could some windows capable person take this for a spin? Unfortunately we can't just push this to the BF and see what it says - our tests don't catch this one... And there's not that much time before the wrap. Anybody have an opinion about adding ifs for WL_SOCKET_CONNECTED to !win32 implementations rather than redefining it to WL_SOCKET_WRITEABLE? - Andres --43cqiovinm32zief Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="connected.diff" diff --git a/src/backend/replication/libpqwalreceiver/libpqwalreceiver.c b/src/backend/replication/libpqwalreceiver/libpqwalreceiver.c index 93dd7b5c17..98e2bc9e1c 100644 --- a/src/backend/replication/libpqwalreceiver/libpqwalreceiver.c +++ b/src/backend/replication/libpqwalreceiver/libpqwalreceiver.c @@ -168,17 +168,21 @@ libpqrcv_connect(const char *conninfo, bool logical, const char *appname, status = PGRES_POLLING_WRITING; do { - /* Wait for socket ready and/or other events. */ - int io_flag; + int io_flag = WL_POSTMASTER_DEATH | WL_LATCH_SET; int rc; - io_flag = (status == PGRES_POLLING_READING - ? WL_SOCKET_READABLE - : WL_SOCKET_WRITEABLE); + if (status == PGRES_POLLING_READING) + io_flag |= WL_SOCKET_READABLE; +#ifdef WIN32 + /* on windows socket initially is not ready for writes */ + else if (PQstatus(conn->streamConn) == CONNECTION_STARTED) + io_flag |= WL_SOCKET_CONNECTED; +#endif + else + io_flag |= WL_SOCKET_WRITEABLE; rc = WaitLatchOrSocket(MyLatch, - WL_POSTMASTER_DEATH | - WL_LATCH_SET | io_flag, + io_flag, PQsocket(conn->streamConn), 0, WAIT_EVENT_LIBPQWALRECEIVER); diff --git a/src/backend/storage/ipc/latch.c b/src/backend/storage/ipc/latch.c index 07b1364de8..03b1dee019 100644 --- a/src/backend/storage/ipc/latch.c +++ b/src/backend/storage/ipc/latch.c @@ -374,11 +374,11 @@ WaitLatchOrSocket(volatile Latch *latch, int wakeEvents, pgsocket sock, AddWaitEventToSet(set, WL_POSTMASTER_DEATH, PGINVALID_SOCKET, NULL, NULL); - if (wakeEvents & (WL_SOCKET_READABLE | WL_SOCKET_WRITEABLE)) + if (wakeEvents & WL_SOCKET_MASK) { int ev; - ev = wakeEvents & (WL_SOCKET_READABLE | WL_SOCKET_WRITEABLE); + ev = wakeEvents & WL_SOCKET_MASK; AddWaitEventToSet(set, ev, sock, NULL, NULL); } @@ -390,8 +390,7 @@ WaitLatchOrSocket(volatile Latch *latch, int wakeEvents, pgsocket sock, { ret |= event.events & (WL_LATCH_SET | WL_POSTMASTER_DEATH | - WL_SOCKET_READABLE | - WL_SOCKET_WRITEABLE); + WL_SOCKET_MASK); } FreeWaitEventSet(set); @@ -640,10 +639,12 @@ FreeWaitEventSet(WaitEventSet *set) * Add an event to the set. Possible events are: * - WL_LATCH_SET: Wait for the latch to be set * - WL_POSTMASTER_DEATH: Wait for postmaster to die - * - WL_SOCKET_READABLE: Wait for socket to become readable - * can be combined in one event with WL_SOCKET_WRITEABLE - * - WL_SOCKET_WRITEABLE: Wait for socket to become writeable - * can be combined with WL_SOCKET_READABLE + * - WL_SOCKET_READABLE: Wait for socket to become readable, + * can be combined in one event with other WL_SOCKET_* events + * - WL_SOCKET_WRITEABLE: Wait for socket to become writeable, + * can be combined with other WL_SOCKET_* events + * - WL_SOCKET_CONNECTED: Wait for socket connection to be established, + * can be combined with WL_SOCKET_* events * * Returns the offset in WaitEventSet->events (starting from 0), which can be * used to modify previously added wait events using ModifyWaitEvent(). @@ -652,9 +653,9 @@ FreeWaitEventSet(WaitEventSet *set) * i.e. it must be a process-local latch initialized with InitLatch, or a * shared latch associated with the current process by calling OwnLatch. * - * In the WL_SOCKET_READABLE/WRITEABLE case, EOF and error conditions are - * reported by returning the socket as readable/writable or both, depending on - * WL_SOCKET_READABLE/WRITEABLE being specified. + * In the WL_SOCKET_READABLE/WRITEABLE/CONNECTED cases, EOF and error + * conditions are reported by returning the socket as readable/writable or + * both, depending on WL_SOCKET_READABLE/WRITEABLE/CONNECTED being specified. * * The user_data pointer specified here will be set for the events returned * by WaitEventSetWait(), allowing to easily associate additional data with @@ -685,8 +686,7 @@ AddWaitEventToSet(WaitEventSet *set, uint32 events, pgsocket fd, Latch *latch, } /* waiting for socket readiness without a socket indicates a bug */ - if (fd == PGINVALID_SOCKET && - (events & (WL_SOCKET_READABLE | WL_SOCKET_WRITEABLE))) + if (fd == PGINVALID_SOCKET && (events & (WL_SOCKET_MASK))) elog(ERROR, "cannot wait on socket event without a socket"); event = &set->events[set->nevents]; @@ -885,6 +885,8 @@ WaitEventAdjustWin32(WaitEventSet *set, WaitEvent *event) flags |= FD_READ; if (event->events & WL_SOCKET_WRITEABLE) flags |= FD_WRITE; + if (event->events & WL_SOCKET_CONNECTED) + flags |= FD_CONNECT; if (*handle == WSA_INVALID_EVENT) { @@ -1395,7 +1397,7 @@ WaitEventSetWaitBlock(WaitEventSet *set, int cur_timeout, returned_events++; } } - else if (cur_event->events & (WL_SOCKET_READABLE | WL_SOCKET_WRITEABLE)) + else if (cur_event->events & WL_SOCKET_MASK) { WSANETWORKEVENTS resEvents; HANDLE handle = set->handles[cur_event->pos + 1]; @@ -1432,6 +1434,12 @@ WaitEventSetWaitBlock(WaitEventSet *set, int cur_timeout, /* writeable */ occurred_events->events |= WL_SOCKET_WRITEABLE; } + if ((cur_event->events & WL_SOCKET_CONNECTED) && + (resEvents.lNetworkEvents & FD_CONNECT)) + { + /* connected */ + occurred_events->events |= WL_SOCKET_CONNECTED; + } if (resEvents.lNetworkEvents & FD_CLOSE) { /* EOF */ @@ -1439,6 +1447,8 @@ WaitEventSetWaitBlock(WaitEventSet *set, int cur_timeout, occurred_events->events |= WL_SOCKET_READABLE; if (cur_event->events & WL_SOCKET_WRITEABLE) occurred_events->events |= WL_SOCKET_WRITEABLE; + if (cur_event->events & WL_SOCKET_CONNECTED) + occurred_events->events |= WL_SOCKET_CONNECTED; } if (occurred_events->events != 0) diff --git a/src/include/storage/latch.h b/src/include/storage/latch.h index 73abfafec5..8af02668e3 100644 --- a/src/include/storage/latch.h +++ b/src/include/storage/latch.h @@ -126,6 +126,16 @@ typedef struct Latch #define WL_SOCKET_WRITEABLE (1 << 2) #define WL_TIMEOUT (1 << 3) /* not for WaitEventSetWait() */ #define WL_POSTMASTER_DEATH (1 << 4) +#ifdef WIN32 +#define WL_SOCKET_CONNECTED (1 << 5) +#else +/* avoid having to to deal with case on platforms not requiring it */ +#define WL_SOCKET_CONNECTED WL_SOCKET_WRITEABLE +#endif + +#define WL_SOCKET_MASK (WL_SOCKET_READABLE | \ + WL_SOCKET_WRITEABLE | \ + WL_SOCKET_CONNECTED) typedef struct WaitEvent { --43cqiovinm32zief Content-Type: text/plain Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs --43cqiovinm32zief--