From: Yann Ylavic Date: Thu, 22 Jul 2021 15:33:19 +0000 (+0000) Subject: core: don't close the socket when failing in ap_start_lingering_close(). X-Git-Tag: 2.5.0-alpha2-ci-test-only~886 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=70d7c7b009c1bbdcd046c1620118f580b6886c5c;p=thirdparty%2Fapache%2Fhttpd.git core: don't close the socket when failing in ap_start_lingering_close(). * 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 --- diff --git a/server/connection.c b/server/connection.c index 19745376db8..b0093e16c9d 100644 --- a/server/connection.c +++ b/server/connection.c @@ -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; }