Skip to content

Commit 64b2c65

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 2ccd8fb commit 64b2c65

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
@@ -286,30 +286,15 @@ socket_close(int code, Datum arg)
286286
secure_close(MyProcPort);
287287

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

0 commit comments

Comments
 (0)