]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Don't explicitly close() the session socket during backend exit; instead
authorTom Lane <tgl@sss.pgh.pa.us>
Thu, 29 May 2003 19:15:34 +0000 (19:15 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Thu, 29 May 2003 19:15:34 +0000 (19:15 +0000)
leave it for the kernel to do after the process dies.  This allows clients
to wait for the backend to exit if they wish (after sending X message,
wait till EOF is detected on the socket).

src/backend/libpq/pqcomm.c

index 27d943715492104e697653fdf49b2be0a8057d48..7f0a9326f1a9bd38de3f4e9846d3d60925e8e3f6 100644 (file)
@@ -30,7 +30,7 @@
  * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- *     $Header: /cvsroot/pgsql/src/backend/libpq/pqcomm.c,v 1.153 2003/05/15 16:35:28 momjian Exp $
+ *     $Header: /cvsroot/pgsql/src/backend/libpq/pqcomm.c,v 1.154 2003/05/29 19:15:34 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -149,9 +149,17 @@ pq_close(void)
 {
        if (MyProcPort != NULL)
        {
+               /* Cleanly shut down SSL layer */
                secure_close(MyProcPort);
-               closesocket(MyProcPort->sock);
-               /* make sure any subsequent attempts to do I/O fail cleanly */
+               /*
+                * Formerly we did an explicit close() here, but it seems better
+                * to leave the socket open until the process dies.  This allows
+                * clients to perform a "synchronous close" if they care --- wait
+                * till the transport layer reports connection closure, and you
+                * can be sure the backend has exited.
+                *
+                * We do set sock to -1 to prevent any further I/O, though.
+                */
                MyProcPort->sock = -1;
        }
 }
@@ -470,6 +478,13 @@ StreamConnection(int server_fd, Port *port)
 
 /*
  * StreamClose -- close a client/backend connection
+ *
+ * NOTE: this is NOT used to terminate a session; it is just used to release
+ * the file descriptor in a process that should no longer have the socket
+ * open.  (For example, the postmaster calls this after passing ownership
+ * of the connection to a child process.)  It is expected that someone else
+ * still has the socket open.  So, we only want to close the descriptor,
+ * we do NOT want to send anything to the far end.
  */
 void
 StreamClose(int sock)