Use other wait events as well

pull/6259/head
Onder Kalaci 2022-08-30 13:35:45 +03:00
parent 820b2a23cd
commit e4a14858a8
1 changed files with 46 additions and 10 deletions

View File

@ -623,10 +623,12 @@ RemoteSocketClosed(MultiConnection *connection)
return false; return false;
} }
int eventCount = 0;
WaitEvent events[3];
WaitEventSet *waitEventSet = WaitEventSet *waitEventSet =
CreateWaitEventSet(CurrentMemoryContext, 1); CreateWaitEventSet(CurrentMemoryContext, 3);
int sock = PQsocket(connection->pgConn); int sock = PQsocket(connection->pgConn);
WaitEvent events[1];
int waitEventSetIndex = int waitEventSetIndex =
CitusAddWaitEventSetToSet(waitEventSet, WL_SOCKET_CLOSED, sock, CitusAddWaitEventSetToSet(waitEventSet, WL_SOCKET_CLOSED, sock,
NULL, (void *) connection); NULL, (void *) connection);
@ -644,18 +646,52 @@ RemoteSocketClosed(MultiConnection *connection)
connection->hostname, connection->hostname,
connection->port, sock))); connection->port, sock)));
FreeWaitEventSet(waitEventSet);
return false; return false;
} }
long timeout = 0; /* do not wait at all */ CitusAddWaitEventSetToSet(waitEventSet, WL_POSTMASTER_DEATH, PGINVALID_SOCKET, NULL,
int eventCount = WaitEventSetWait(waitEventSet, timeout, events, NULL);
1, WAIT_EVENT_CLIENT_READ); CitusAddWaitEventSetToSet(waitEventSet, WL_LATCH_SET, PGINVALID_SOCKET, MyLatch,
if (eventCount > 0) NULL);
{
Assert(eventCount == 1);
WaitEvent *event = &events[0]; long timeout = 0; /* do not wait at all */
socketClosed = (event->events & WL_SOCKET_CLOSED); int eventIndex = 0;
retry:
eventCount =
WaitEventSetWait(waitEventSet, timeout, events,
3, WAIT_EVENT_CLIENT_READ);
for (; eventIndex < eventCount; eventIndex++)
{
WaitEvent *event = &events[eventIndex];
if (event->events & WL_POSTMASTER_DEATH)
{
ereport(ERROR, (errmsg("postmaster was shut down, exiting")));
}
if (event->events & WL_SOCKET_CLOSED)
{
socketClosed = true;
/* we found what we are searching for */
break;
}
if (event->events & WL_LATCH_SET)
{
/*
* A latch event might be preventing other events from being
* reported. Reset it and poll again. No need to restore it
* because no code should expect latches to survive across
* CHECK_FOR_INTERRUPTS().
*/
ResetLatch(MyLatch);
goto retry;
}
} }
FreeWaitEventSet(waitEventSet); FreeWaitEventSet(waitEventSet);