From: Tom Lane Date: Tue, 15 May 2012 03:51:34 +0000 (-0400) Subject: In pgstat.c, use a timeout in WaitLatchOrSocket only on Windows. X-Git-Tag: REL9_2_BETA2~77 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9b63e9869ffaa4d6d3e8bf45086a765d8f310f1c;p=postgresql 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. --- diff --git a/src/backend/postmaster/pgstat.c b/src/backend/postmaster/pgstat.c index bb7c61b058..424cfcaf4f 100644 --- a/src/backend/postmaster/pgstat.c +++ b/src/backend/postmaster/pgstat.c @@ -3113,7 +3113,8 @@ PgstatCollectorMain(int argc, char *argv[]) * Try to receive and process a message. This will not block, * since the socket is set to non-blocking mode. * - * XXX On Windows, we have to force pgwin32_recv to cooperate. + * XXX On Windows, we have to force pgwin32_recv to cooperate, + * despite the previous use of pg_set_noblock() on the socket. * This is extremely broken and should be fixed someday. */ #ifdef WIN32 @@ -3231,11 +3232,27 @@ PgstatCollectorMain(int argc, char *argv[]) } /* end of inner message-processing loop */ /* Sleep until there's something to do */ - /* XXX should not need a timeout here */ +#ifndef WIN32 + wr = WaitLatchOrSocket(&pgStatLatch, + WL_LATCH_SET | WL_POSTMASTER_DEATH | WL_SOCKET_READABLE, + pgStatSock, + -1L); +#else + /* + * Windows, at least in its Windows Server 2003 R2 incarnation, + * sometimes loses FD_READ events. Waking up and retrying the recv() + * fixes that, so don't sleep indefinitely. This is a crock of the + * first water, but until somebody wants to debug exactly what's + * happening there, this is the best we can do. The two-second + * timeout matches our pre-9.2 behavior, and needs to be short enough + * to not provoke "pgstat wait timeout" complaints from + * backend_read_statsfile. + */ wr = WaitLatchOrSocket(&pgStatLatch, WL_LATCH_SET | WL_POSTMASTER_DEATH | WL_SOCKET_READABLE | WL_TIMEOUT, pgStatSock, - 2000L); + 2 * 1000L /* msec */); +#endif /* * Emergency bailout if postmaster has died. This is to avoid the