From 5cc5869ea45f39db1f2cee45925e88731d0a75b0 Mon Sep 17 00:00:00 2001 From: Yann Ylavic Date: Mon, 9 Jun 2014 01:03:39 +0000 Subject: [PATCH] mod_proxy: Shutdown (eg. SSL close notify) the backend connection before closing. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1601291 13f79535-47bb-0310-9956-ffa450edef68 --- CHANGES | 3 +++ docs/log-message-tags/next-number | 2 +- modules/proxy/proxy_util.c | 33 +++++++++++++++++++++++++++++++ 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/CHANGES b/CHANGES index 52af761c88..b87c8b692f 100644 --- a/CHANGES +++ b/CHANGES @@ -1,6 +1,9 @@ -*- coding: utf-8 -*- Changes with Apache 2.5.0 + *) mod_proxy: Shutdown (eg. close notify) the backend connection before + closing. [Yann Ylavic] + *) mpm_event[opt]: Send the SSL close notify alert when the KeepAliveTimeout expires. PR54998. [Yann Ylavic] diff --git a/docs/log-message-tags/next-number b/docs/log-message-tags/next-number index f570f1c66f..a54a3cb83c 100644 --- a/docs/log-message-tags/next-number +++ b/docs/log-message-tags/next-number @@ -1 +1 @@ -2642 +2643 diff --git a/modules/proxy/proxy_util.c b/modules/proxy/proxy_util.c index 5bd9a4b2a4..513b865719 100644 --- a/modules/proxy/proxy_util.c +++ b/modules/proxy/proxy_util.c @@ -2815,6 +2815,33 @@ PROXY_DECLARE(int) ap_proxy_connect_backend(const char *proxy_function, return connected ? OK : DECLINED; } +static apr_status_t connection_shutdown(void *theconn) +{ + proxy_conn_rec *conn = (proxy_conn_rec *)theconn; + conn_rec *c = conn->connection; + if (c) { + if (!c->aborted) { + apr_interval_time_t saved_timeout = 0; + apr_socket_timeout_get(conn->sock, &saved_timeout); + if (saved_timeout) { + apr_socket_timeout_set(conn->sock, 0); + } + + (void)ap_shutdown_conn(c, 0); + c->aborted = 1; + + if (saved_timeout) { + apr_socket_timeout_set(conn->sock, saved_timeout); + } + } + + ap_log_cerror(APLOG_MARK, APLOG_DEBUG, 0, c, APLOGNO(02642) + "proxy: connection shutdown"); + } + return APR_SUCCESS; +} + + PROXY_DECLARE(int) ap_proxy_connection_create(const char *proxy_function, proxy_conn_rec *conn, conn_rec *c, @@ -2887,6 +2914,12 @@ PROXY_DECLARE(int) ap_proxy_connection_create(const char *proxy_function, } apr_socket_timeout_set(conn->sock, current_timeout); + /* Shutdown the connection before closing it (eg. SSL connections + * need to be close-notify-ed). + */ + apr_pool_cleanup_register(conn->scpool, conn, connection_shutdown, + apr_pool_cleanup_null); + return OK; } -- 2.40.0