From f4b072d276589b9899d004306f65b6e1baf6d2cc Mon Sep 17 00:00:00 2001 From: Stefan Eissing Date: Mon, 26 Oct 2015 13:19:40 +0000 Subject: [PATCH] improved timeout handling on main connection, shorter lingering close, conn_state set before read git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1710594 13f79535-47bb-0310-9956-ffa450edef68 --- modules/http2/h2_conn.c | 26 +++++++++++++++++--------- modules/http2/h2_h2.c | 2 +- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/modules/http2/h2_conn.c b/modules/http2/h2_conn.c index 4cd29c9b38..816801c336 100644 --- a/modules/http2/h2_conn.c +++ b/modules/http2/h2_conn.c @@ -40,7 +40,7 @@ static struct h2_workers *workers; -static apr_status_t h2_session_process(h2_session *session); +static apr_status_t h2_conn_loop(h2_session *session); static h2_mpm_type_t mpm_type = H2_MPM_UNKNOWN; static module *mpm_module; @@ -150,7 +150,7 @@ apr_status_t h2_conn_rprocess(request_rec *r) return APR_EGENERAL; } - return h2_session_process(session); + return h2_conn_loop(session); } apr_status_t h2_conn_main(conn_rec *c) @@ -176,7 +176,7 @@ apr_status_t h2_conn_main(conn_rec *c) NGHTTP2_INADEQUATE_SECURITY, NULL, 0); } - status = h2_session_process(session); + status = h2_conn_loop(session); /* Make sure this connection gets closed properly. */ c->keepalive = AP_CONN_CLOSE; @@ -187,7 +187,7 @@ apr_status_t h2_conn_main(conn_rec *c) return status; } -apr_status_t h2_session_process(h2_session *session) +static apr_status_t h2_conn_loop(h2_session *session) { apr_status_t status = APR_SUCCESS; int rv = 0; @@ -282,10 +282,15 @@ apr_status_t h2_session_process(h2_session *session) * submit our settings and need the ACK. */ got_streams = !h2_stream_set_is_empty(session->streams); - status = h2_session_read(session, - (!got_streams - || session->frames_received <= 1)? - APR_BLOCK_READ : APR_NONBLOCK_READ); + if (!got_streams || session->frames_received <= 1) { + session->c->cs->state = CONN_STATE_WRITE_COMPLETION; + status = h2_session_read(session, APR_BLOCK_READ); + } + else { + session->c->cs->state = CONN_STATE_HANDLER; + status = h2_session_read(session, APR_NONBLOCK_READ); + } + switch (status) { case APR_SUCCESS: /* successful read, reset our idle timers */ have_read = 1; @@ -303,6 +308,10 @@ apr_status_t h2_session_process(h2_session *session) ap_log_cerror( APLOG_MARK, APLOG_DEBUG, status, session->c, "h2_session(%ld): terminating", session->id); + /* Stolen from mod_reqtimeout to speed up lingering when + * a read timeout happened. + */ + apr_table_setn(session->c->notes, "short-lingering-close", "1"); } else { /* uncommon status, log on INFO so that we see this */ @@ -463,7 +472,6 @@ apr_status_t h2_conn_process(conn_rec *c, apr_socket_t *socket) { AP_DEBUG_ASSERT(c); - c->clogging_input_filters = 1; ap_process_connection(c, socket); return APR_SUCCESS; diff --git a/modules/http2/h2_h2.c b/modules/http2/h2_h2.c index 6ee067dedc..156d1902b7 100644 --- a/modules/http2/h2_h2.c +++ b/modules/http2/h2_h2.c @@ -548,7 +548,7 @@ void h2_h2_register_hooks(void) ap_hook_post_read_request(h2_h2_post_read_req, NULL, NULL, APR_HOOK_REALLY_FIRST); } -int h2_h2_remove_timeout(conn_rec* c) +static int h2_h2_remove_timeout(conn_rec* c) { h2_ctx *ctx = h2_ctx_get(c); -- 2.50.1