]> git.ipfire.org Git - thirdparty/apache/httpd.git/commitdiff
core: don't close the socket when failing in ap_start_lingering_close().
authorYann Ylavic <ylavic@apache.org>
Thu, 22 Jul 2021 15:33:19 +0000 (15:33 +0000)
committerYann Ylavic <ylavic@apache.org>
Thu, 22 Jul 2021 15:33:19 +0000 (15:33 +0000)
* server/connection.c (ap_start_lingering_close): Don't apr_socket_close().

* server/connection.c (ap_lingering_close): Do apr_socket_close() on
  ap_start_lingering_close() failure.

On failure ap_start_lingering_close() did not consistently close the socket,
so the caller had to call apr_socket_close() too with possible/unreliable
EBADF.  The only upstream callers of ap_start_lingering_close() are MPM event
and ap_start_lingering_close(), but any third-party user has this issue so the
change should't break anyone.

Follow up to r1891716.
Github: #208

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1891721 13f79535-47bb-0310-9956-ffa450edef68

server/connection.c

index 19745376db8a1e363949b854c77c133b2e8755cf..b0093e16c9d053b570f33e4eccc1206f83674fd3 100644 (file)
@@ -139,18 +139,12 @@ AP_DECLARE(int) ap_start_lingering_close(conn_rec *c)
     ap_flush_conn(c);
 
 #ifdef NO_LINGCLOSE
-    apr_socket_close(csd);
     return 1;
 #else
     /* Shut down the socket for write, which will send a FIN
      * to the peer.
      */
-    if (c->aborted
-            || apr_socket_shutdown(csd, APR_SHUTDOWN_WRITE) != APR_SUCCESS) {
-        apr_socket_close(csd);
-        return 1;
-    }
-    return 0;
+    return (c->aborted || apr_socket_shutdown(csd, APR_SHUTDOWN_WRITE));
 #endif
 }
 
@@ -162,6 +156,7 @@ AP_DECLARE(void) ap_lingering_close(conn_rec *c)
     apr_socket_t *csd = ap_get_conn_socket(c);
 
     if (ap_start_lingering_close(c)) {
+        apr_socket_close(csd);
         return;
     }