Skip to content

Commit 9b63e98

Browse files
committed
In pgstat.c, use a timeout in WaitLatchOrSocket only on Windows.
We have no need for a timeout here really, but some broken products from Redmond seem to lose FD_READ events occasionally, and waking up and retrying the recv() is the only known way to work around that. Perhaps somebody will be motivated to figure out a better answer here; but not I.
1 parent 5a2bb06 commit 9b63e98

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

src/backend/postmaster/pgstat.c

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3113,7 +3113,8 @@ PgstatCollectorMain(int argc, char *argv[])
31133113
* Try to receive and process a message. This will not block,
31143114
* since the socket is set to non-blocking mode.
31153115
*
3116-
* XXX On Windows, we have to force pgwin32_recv to cooperate.
3116+
* XXX On Windows, we have to force pgwin32_recv to cooperate,
3117+
* despite the previous use of pg_set_noblock() on the socket.
31173118
* This is extremely broken and should be fixed someday.
31183119
*/
31193120
#ifdef WIN32
@@ -3231,11 +3232,27 @@ PgstatCollectorMain(int argc, char *argv[])
32313232
} /* end of inner message-processing loop */
32323233

32333234
/* Sleep until there's something to do */
3234-
/* XXX should not need a timeout here */
3235+
#ifndef WIN32
3236+
wr = WaitLatchOrSocket(&pgStatLatch,
3237+
WL_LATCH_SET | WL_POSTMASTER_DEATH | WL_SOCKET_READABLE,
3238+
pgStatSock,
3239+
-1L);
3240+
#else
3241+
/*
3242+
* Windows, at least in its Windows Server 2003 R2 incarnation,
3243+
* sometimes loses FD_READ events. Waking up and retrying the recv()
3244+
* fixes that, so don't sleep indefinitely. This is a crock of the
3245+
* first water, but until somebody wants to debug exactly what's
3246+
* happening there, this is the best we can do. The two-second
3247+
* timeout matches our pre-9.2 behavior, and needs to be short enough
3248+
* to not provoke "pgstat wait timeout" complaints from
3249+
* backend_read_statsfile.
3250+
*/
32353251
wr = WaitLatchOrSocket(&pgStatLatch,
32363252
WL_LATCH_SET | WL_POSTMASTER_DEATH | WL_SOCKET_READABLE | WL_TIMEOUT,
32373253
pgStatSock,
3238-
2000L);
3254+
2 * 1000L /* msec */);
3255+
#endif
32393256

32403257
/*
32413258
* Emergency bailout if postmaster has died. This is to avoid the

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy