On Windows, also call shutdown() while closing the client socket.
authorTom Lane <[email protected]>
Tue, 7 Dec 2021 18:34:06 +0000 (13:34 -0500)
committerTom Lane <[email protected]>
Tue, 7 Dec 2021 18:34:32 +0000 (13:34 -0500)
Further experimentation shows that commit 6051857fc 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

src/backend/libpq/pqcomm.c

index 5f1014da271bb7b381ebcbf7cd6e9c705d15536f..4fdda9f444ee243744aea92f620d6c3adc67b425 100644 (file)
@@ -299,7 +299,8 @@ socket_close(int code, Datum arg)
         * not yet sent to the client.  (This is a flat-out violation of the
         * TCP RFCs, but count on Microsoft not to care about that.)  To get
         * the spec-compliant "graceful shutdown" behavior, we must invoke
-        * closesocket() explicitly.
+        * closesocket() explicitly.  When using OpenSSL, it seems that clean
+        * shutdown also requires an explicit shutdown() call.
         *
         * This code runs late enough during process shutdown that we should
         * have finished all externally-visible shutdown activities, so that
@@ -307,6 +308,7 @@ socket_close(int code, Datum arg)
         * Windows too.  But it's a lot more fragile than the other way.
         */
 #ifdef WIN32
+       shutdown(MyProcPort->sock, SD_SEND);
        closesocket(MyProcPort->sock);
 #endif