postgresql/src/backend/storage
Thomas Munro a8458f508a 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
2024-07-13 14:59:46 +12:00
..
aio Fix typos and incorrect type in read_stream.c 2024-05-01 17:04:52 +12:00
buffer Fix RBM_ZERO_AND_LOCK. 2024-06-10 12:32:59 +12:00
file Remove incorrect Asserts in buffile.c 2024-07-04 09:44:34 +12:00
freespace freespace: Don't return blocks past the end of the main fork. 2024-04-13 08:34:20 -07:00
ipc Fix lost Windows socket EOF events. 2024-07-13 14:59:46 +12:00
large_object Remove unused #include's from backend .c files 2024-03-04 12:02:20 +01:00
lmgr Lift limitation that PGPROC->links must be the first field 2024-07-05 11:21:46 +03:00
page Update copyright for 2024 2024-01-03 20:49:05 -05:00
smgr Improve assertion in mdwritev() 2024-06-04 07:15:10 +09:00
sync Make the order of the header file includes consistent 2024-03-13 15:07:00 +01:00
Makefile Provide API for streaming relation data. 2024-04-03 00:49:46 +13:00
meson.build Provide API for streaming relation data. 2024-04-03 00:49:46 +13:00