On Mon, Jan 10, 2022 at 8:06 AM Thomas Munro <thomas.mu...@gmail.com> wrote: > On Mon, Jan 10, 2022 at 12:00 AM Alexander Lakhin <exclus...@gmail.com> wrote: > > Going down through the call chain, I see that at the end of it > > WaitForMultipleObjects() hangs while waiting for the primary connection > > socket event. So it looks like the socket, that is closed by the > > primary, can get into a state unsuitable for WaitForMultipleObjects(). > > I wonder if FD_CLOSE is edge-triggered, and it's already told us once.
Can you reproduce it with this patch?
From d3cfff53911ce068d4a31fe7ac7933958936d1b0 Mon Sep 17 00:00:00 2001 From: Thomas Munro <thomas.mu...@gmail.com> Date: Mon, 10 Jan 2022 14:45:05 +1300 Subject: [PATCH] Make Windows FD_CLOSE reporting sticky. XXX Just testing an idea... --- src/backend/storage/ipc/latch.c | 16 ++++++++++++++++ src/include/storage/latch.h | 1 + 2 files changed, 17 insertions(+) diff --git a/src/backend/storage/ipc/latch.c b/src/backend/storage/ipc/latch.c index 1d893cf863..4a61b31cd5 100644 --- a/src/backend/storage/ipc/latch.c +++ b/src/backend/storage/ipc/latch.c @@ -899,6 +899,7 @@ AddWaitEventToSet(WaitEventSet *set, uint32 events, pgsocket fd, Latch *latch, event->user_data = user_data; #ifdef WIN32 event->reset = false; + event->closed = false; #endif if (events == WL_LATCH_SET) @@ -1882,6 +1883,20 @@ WaitEventSetWaitBlock(WaitEventSet *set, int cur_timeout, return 1; } } + + /* + * XXX: HYPOTHESIS TO TEST + * Windows only reports FD_CLOSE once. If we've seen that already, + * continue to report it. + */ + if ((cur_event & WL_SOCKET_MASK) && cur_event->closed) + { + occurred_events->pos = cur_event->pos; + occurred_events->user_data = cur_event->user_data; + occurred_events->events = (cur_event->events & WL_SOCKET_MASK); + occurred_events->fd = cur_event->fd; + return 1; + } } /* @@ -2002,6 +2017,7 @@ WaitEventSetWaitBlock(WaitEventSet *set, int cur_timeout, { /* EOF/error, so signal all caller-requested socket flags */ occurred_events->events |= (cur_event->events & WL_SOCKET_MASK); + cur_event->closed = true; } if (occurred_events->events != 0) diff --git a/src/include/storage/latch.h b/src/include/storage/latch.h index 44f9368c64..c24f46dc37 100644 --- a/src/include/storage/latch.h +++ b/src/include/storage/latch.h @@ -147,6 +147,7 @@ typedef struct WaitEvent void *user_data; /* pointer provided in AddWaitEventToSet */ #ifdef WIN32 bool reset; /* Is reset of the event required? */ + bool closed; /* Has FD_CLOSE event been reported? */ #endif } WaitEvent; -- 2.33.1