Skip to content

Commit 75674c7

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 357ff66 commit 75674c7

File tree

1 file changed

+7
-22
lines changed

1 file changed

+7
-22
lines changed

src/backend/libpq/pqcomm.c

+7-22
Original file line numberDiff line numberDiff line change
@@ -277,30 +277,15 @@ socket_close(int code, Datum arg)
277277
secure_close(MyProcPort);
278278

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

0 commit comments

Comments
 (0)