Skip to content

Commit bbb1caf

Browse files
committed
Revert "graceful shutdown" changes for Windows, in back branches only.
This reverts commits 6051857 and ed52c37, but only in the back branches. Further testing has shown that while those changes do fix some things, they also break others; in particular, it looks like walreceivers fail to detect walsender-initiated connection close reliably if the walsender shuts down this way. We'll keep trying to improve matters in HEAD, but it now seems unwise to push these changes into stable releases. Discussion: https://postgr.es/m/CA+hUKG+OeoETZQ=Qw5Ub5h3tmwQhBmDA=nuNO3KG=zWfUypFAw@mail.gmail.com
1 parent acd4f44 commit bbb1caf

File tree

1 file changed

+7
-22
lines changed

1 file changed

+7
-22
lines changed

src/backend/libpq/pqcomm.c

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -289,30 +289,15 @@ socket_close(int code, Datum arg)
289289
secure_close(MyProcPort);
290290

291291
/*
292-
* On most platforms, we leave the socket open until the process dies.
293-
* This allows clients to perform a "synchronous close" if they care
294-
* --- wait till the transport layer reports connection closure, and
295-
* you can be sure the backend has exited. Saves a kernel call, too.
292+
* Formerly we did an explicit close() here, but it seems better to
293+
* leave the socket open until the process dies. This allows clients
294+
* to perform a "synchronous close" if they care --- wait till the
295+
* transport layer reports connection closure, and you can be sure the
296+
* backend has exited.
296297
*
297-
* However, that does not work on Windows: if the kernel closes the
298-
* socket it will invoke an "abortive shutdown" that discards any data
299-
* not yet sent to the client. (This is a flat-out violation of the
300-
* TCP RFCs, but count on Microsoft not to care about that.) To get
301-
* the spec-compliant "graceful shutdown" behavior, we must invoke
302-
* closesocket() explicitly. When using OpenSSL, it seems that clean
303-
* shutdown also requires an explicit shutdown() call.
304-
*
305-
* This code runs late enough during process shutdown that we should
306-
* have finished all externally-visible shutdown activities, so that
307-
* in principle it's good enough to act as a synchronous close on
308-
* Windows too. But it's a lot more fragile than the other way.
298+
* We do set sock to PGINVALID_SOCKET to prevent any further I/O,
299+
* though.
309300
*/
310-
#ifdef WIN32
311-
shutdown(MyProcPort->sock, SD_SEND);
312-
closesocket(MyProcPort->sock);
313-
#endif
314-
315-
/* In any case, set sock to PGINVALID_SOCKET to prevent further I/O */
316301
MyProcPort->sock = PGINVALID_SOCKET;
317302
}
318303
}

0 commit comments

Comments
 (0)