pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Thomas Munro <tmunro@postgresql.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Fix lost Windows socket EOF events.
Date: Sat, 13 Jul 2024 04:14:44 +0000
Message-ID: <E1sSU9k-001SKN-8W@gemulon.postgresql.org> (raw)

Fix lost Windows socket EOF events.

Winsock only signals an FD_CLOSE event once if the other end of the
socket shuts down gracefully.  Because each WaitLatchOrSocket() call
constructs and destroys a new event handle every time, with unlucky
timing we can lose it and hang.  We get away with this only if the other
end disconnects non-gracefully, because FD_CLOSE is repeatedly signaled
in that case.

To fix this design flaw in our Windows socket support fundamentally,
we'd probably need to rearchitect it so that a single event handle
exists for the lifetime of a socket, or switch to completely different
multiplexing or async I/O APIs.  That's going to be a bigger job
and probably wouldn't be back-patchable.

This brute force kludge closes the race by explicitly polling with
MSG_PEEK before sleeping.

Back-patch to all supported releases.  This should hopefully clear up
some random build farm and CI hang failures reported over the years.  It
might also allow us to try using graceful shutdown in more places again
(reverted in commit 29992a6) to fix instability in the transmission of
FATAL error messages, but that isn't done by this commit.

Reported-by: Tom Lane <tgl@sss.pgh.pa.us>
Tested-by: Alexander Lakhin <exclusion@gmail.com>
Discussion: https://postgr.es/m/176008.1715492071%40sss.pgh.pa.us

Branch
------
REL_17_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/3c1c82d4066e19a2841fb5f0529452de0d4d65b2

Modified Files
--------------
src/backend/storage/ipc/latch.c | 32 ++++++++++++++++++++++++++++++++
1 file changed, 32 insertions(+)



view thread (7+ messages)  latest in thread

Message-ID: <E1sSU9k-001SKN-8W@gemulon.postgresql.org>
Permalink:  ../E1sSU9k-001SKN-8W@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1sSU9k-001SKN-8W@gemulon.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-committers@postgresql.org
  Cc: tmunro@postgresql.org, pgsql-committers@lists.postgresql.org
  Subject: Re: pgsql: Fix lost Windows socket EOF events.
  In-Reply-To: <E1sSU9k-001SKN-8W@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox