Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1n8TBz-0003OY-1Y for pgsql-hackers@arkaria.postgresql.org; Fri, 14 Jan 2022 20:28:59 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1n8TBx-0001Rt-L3 for pgsql-hackers@arkaria.postgresql.org; Fri, 14 Jan 2022 20:28:57 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1n8TBv-0001Rk-K7 for pgsql-hackers@lists.postgresql.org; Fri, 14 Jan 2022 20:28:57 +0000 Received: from out5-smtp.messagingengine.com ([66.111.4.29]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1n8TBs-00026v-HS for pgsql-hackers@postgresql.org; Fri, 14 Jan 2022 20:28:54 +0000 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.nyi.internal (Postfix) with ESMTP id 136F05C0110; Fri, 14 Jan 2022 15:28:51 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute3.internal (MEProxy); Fri, 14 Jan 2022 15:28:51 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=anarazel.de; h= date:from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; s=fm3; bh=eMUpr2IDLGIxZI49wMmqRDB3s/S 423wKDlwfghtHcSc=; b=KC9SaU2pVgIZc1pH+Qh8E9UzYsEH7FpTkp3w9d/57hH vyFHwRrq638xQY48C1ulC8F+XUoZ+HmQheGCFUUKsFabK2UdNg6VuGtS+8GT8jLN 094Wo0LZ0LULmy8RB60Ydkpaq41DsaMBUZoCq3waN+fv5joeGqgZcLeIyLnp5Nut HIutOkAfg8wPMyMBysxN7JZQNE5QtmY9uDZiKU8VYAY96fMcvW68sDpbz1JQ+9Vx S+ioJqFZfuATjp1rsWHYX+hwgorA4qOeCBoeMTgDFej1ZHhmVCGKsWmfQwq1dMZ4 ACLHsvmG2R+vJ+WAURMvg8MAid+wu3S9Fm5u7wmR2BA== 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-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; bh=eMUpr2 IDLGIxZI49wMmqRDB3s/S423wKDlwfghtHcSc=; b=Dz+qJv9mwjKIUGR/msnNk2 xLv8hmydLwP0o/XO9XfAVe3BaUHjDROrkjVd8VrDUi2h3vvefhmLKnLjB3z5+LGM NM0dCScNNlV6yjiQXWUgK6LrEm5MH6jJznVHga/78GUS/QACbACNLvC/sD2wk76G 2fBO9FXPm7XBOJOrOosFzkdW5zah3KJ5dQRzsY152P18ZiQ6QymL43SVbyLK0nTo rHOZ9CJ56cQUVFlTba9oAJK/VZgfe4pXei3x8qe0D3gW0yDr81mod2hCzn6xxH25 rKL/b107QSsu4qP8Jz4NuQo6VGHxHjf1w4zdQ6+ZK6BE8Z3OSt5ueppaXsF7azdw == X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvvddrtdehgddufeekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvffukfhfgggtuggjsehttdertddttddvnecuhfhrohhmpeetnhgurhgv shcuhfhrvghunhguuceorghnughrvghssegrnhgrrhgriigvlhdruggvqeenucggtffrrg htthgvrhhnpedvhffgkeejudfgjedtveeigfehueeuleehudfgffdvvdfhvedufedujeff keetueenucffohhmrghinhepmhhitghrohhsohhfthdrtghomhenucevlhhushhtvghruf hiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegrnhgurhgvshesrghnrghrrgii vghlrdguvg X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 14 Jan 2022 15:28:49 -0500 (EST) Date: Fri, 14 Jan 2022 12:28:48 -0800 From: Andres Freund To: Thomas Munro Cc: Alexander Lakhin , Tom Lane , Andrew Dunstan , pgsql-hackers Subject: Re: Why is src/test/modules/committs/t/002_standby.pl flaky? Message-ID: <20220114202848.x2ctpjgyreqx22dv@alap3.anarazel.de> References: <5d507424-13ce-d19f-2f5d-ab4c6a987316@gmail.com> <1fe6b898-1722-d190-03c0-bf4c4884a748@gmail.com> <2763901.1641932210@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, On 2022-01-14 20:31:22 +1300, Thomas Munro wrote: > Andres and I chatted about this stuff off list and he pointed out > something else about the wrappers in socket.c: there are more paths in > there that work with socket events, which means more ways to lose the > precious FD_CLOSE event. I think it doesn't even need to touch socket.c to cause breakage. Using two different WaitEventSets is enough. https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-wsaeventselect says: > The FD_CLOSE network event is recorded when a close indication is received > for the virtual circuit corresponding to the socket. In TCP terms, this > means that the FD_CLOSE is recorded when the connection goes into the TIME > WAIT or CLOSE WAIT states. This results from the remote end performing a > shutdown on the send side or a closesocket. FD_CLOSE being posted after all > data is read from a socket So FD_CLOSE is *recorded* internally when the connection is closed. But only posted to the visible event once all data is read. All good so far. But combine that with: > Issuing a WSAEventSelect for a socket cancels any previous WSAAsyncSelect or > WSAEventSelect for the same socket and clears the internal network event > record. Note the bit about clearing the internal network event record. Which seems to pretty precisely explain why we're loosing FD_CLOSEs? And it does also explain why this is more likely after the shutdown changes: It's more likely the network stack knows it has readable data *and* that the connection closed. Which is recorded in the "internal network event record". But once all the data is read, walsender.c will do another WaitLatchOrSocket(), which does WSAEventSelect(), clearing the "internal event record" and loosing the FD_CLOSE. My first inclination was that we ought to wrap the socket created for windows in pgwin32_socket() in a custom type with some additional data - including information about already received events, an EVENT, etc. I think that might help to remove a lot of the messy workarounds we have in socket.c etc. But: It wouldn't do much good here, because the socket is not a socket created by socket.c but by libpq :(. Greetings, Andres Freund