]> git.ipfire.org Git - thirdparty/postgresql.git/commit
Fix lost Windows socket EOF events.
authorThomas Munro <tmunro@postgresql.org>
Sat, 13 Jul 2024 02:59:46 +0000 (14:59 +1200)
committerThomas Munro <tmunro@postgresql.org>
Sat, 13 Jul 2024 03:28:38 +0000 (15:28 +1200)
commit5546a834cc6fa49057356eb90ecbd9ee12d7d58a
tree11557df5442b59288f95e5f0f14621f770f240fd
parent9f0f72d89ff6cff8261fd793257147cbb268a6ae
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
src/backend/storage/ipc/latch.c