Skip to content

Commit 23bc57d

Browse files
committed
On Windows, also call shutdown() while closing the client socket.
Further experimentation shows that commit 6051857 is not sufficient when using (some versions of?) OpenSSL. The reason is obscure, but calling shutdown(socket, SD_SEND) improves matters. Per testing by Andrew Dunstan and Alexander Lakhin. Back-patch as before. Discussion: https://postgr.es/m/af5e0bf3-6a61-bb97-6cba-061ddf22ff6b@dunslane.net
1 parent 7b0643c commit 23bc57d

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/backend/libpq/pqcomm.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,14 +299,16 @@ socket_close(int code, Datum arg)
299299
* not yet sent to the client. (This is a flat-out violation of the
300300
* TCP RFCs, but count on Microsoft not to care about that.) To get
301301
* the spec-compliant "graceful shutdown" behavior, we must invoke
302-
* closesocket() explicitly.
302+
* closesocket() explicitly. When using OpenSSL, it seems that clean
303+
* shutdown also requires an explicit shutdown() call.
303304
*
304305
* This code runs late enough during process shutdown that we should
305306
* have finished all externally-visible shutdown activities, so that
306307
* in principle it's good enough to act as a synchronous close on
307308
* Windows too. But it's a lot more fragile than the other way.
308309
*/
309310
#ifdef WIN32
311+
shutdown(MyProcPort->sock, SD_SEND);
310312
closesocket(MyProcPort->sock);
311313
#endif
312314

0 commit comments

Comments
 (0)