postgresql/src/backend
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
..
access Assign error codes where missing for user-facing failures 2024-07-04 09:48:40 +09:00
archive Fix memory leaks in error reporting with LOG level 2024-05-14 10:41:32 +02:00
backup Fix limit block handling in pg_wal_summary_contents(). 2024-07-09 09:26:54 +09:00
bootstrap Remove unused #include's from backend .c files 2024-03-04 12:02:20 +01:00
catalog Extend pg_get_acl() to handle sub-object IDs 2024-07-10 10:14:37 +09:00
commands Fix ALTER TABLE DETACH for inconsistent indexes 2024-07-12 12:54:01 +02:00
executor Show Parallel Bitmap Heap Scan worker stats in EXPLAIN ANALYZE 2024-07-09 12:15:47 +12:00
foreign Remove unused #include's from backend .c files 2024-03-04 12:02:20 +01:00
jit SQL/JSON: Always coerce JsonExpr result at runtime 2024-06-28 21:58:13 +09:00
lib Revert: Implement pg_wal_replay_wait() stored procedure 2024-04-11 17:28:15 +03:00
libpq Assign error codes where missing for user-facing failures 2024-07-04 09:48:40 +09:00
main Tighten check for --forkchild argument when spawning child process 2024-07-03 15:53:30 +03:00
nodes SQL/JSON: Always coerce JsonExpr result at runtime 2024-06-28 21:58:13 +09:00
optimizer Consider materializing the cheapest inner path in parallel nestloop 2024-07-12 11:16:43 +09:00
parser SQL/JSON: Fix some obsolete comments. 2024-07-04 16:05:35 +09:00
partitioning Fix creation of partition descriptor during concurrent detach 2024-06-11 11:38:45 +02:00
po Translation updates 2024-06-24 13:11:27 +02:00
port Revise GUC names quoting in messages again 2024-05-17 11:44:26 +02:00
postmaster Avoid 0-length memcpy to NULL with EXEC_BACKEND 2024-07-03 15:58:14 +03:00
regex Support C.UTF-8 locale in the new builtin collation provider. 2024-03-19 15:24:41 -07:00
replication Fix a typo in logicalrep_write_typ(). 2024-07-12 10:20:59 +05:30
rewrite Fix assorted bugs related to identity column in partitioned tables 2024-05-07 22:50:00 +02:00
snowball Remove unused #include's from backend .c files 2024-03-04 12:02:20 +01:00
statistics Fix typos and duplicate words 2024-04-18 21:28:07 +02:00
storage Fix lost Windows socket EOF events. 2024-07-13 14:59:46 +12:00
tcop Remove redundant SetProcessingMode(InitProcessing) calls 2024-07-02 20:14:40 +03:00
tsearch Remove unused #include's from backend .c files 2024-03-04 12:02:20 +01:00
utils Add assertion in pgstat_write_statsfile() about processes allowed 2024-07-12 15:09:53 +09:00
.gitignore Add .gitignore entries for AIX-specific intermediate build artifacts. 2015-07-08 20:44:22 -04:00
common.mk Blind attempt to fix LLVM dependency in the backend 2022-09-15 10:53:48 +07:00
Makefile Fix make build on MinGW 2024-06-21 08:17:23 +02:00
meson.build meson: Fix import library name in Windows 2024-06-20 09:08:36 +02:00
nls.mk Add missing gettext triggers 2024-05-14 12:57:22 +02:00