From 0a7dfee5f1dd9b82674cb801ce17c068afdc7922 Mon Sep 17 00:00:00 2001 From: Yann Ylavic Date: Thu, 29 Sep 2016 08:15:33 +0000 Subject: event: follow up to r1762718. We still need to kill kept-alive connections in normal/expiry processing if the workers are busy or dying. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1762742 13f79535-47bb-0310-9956-ffa450edef68 --- server/mpm/event/event.c | 41 ++++++++++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 15 deletions(-) (limited to 'server') diff --git a/server/mpm/event/event.c b/server/mpm/event/event.c index 66b1689678..7decebd41c 100644 --- a/server/mpm/event/event.c +++ b/server/mpm/event/event.c @@ -1796,6 +1796,23 @@ static void process_timeout_queue(struct timeout_queue *q, apr_thread_mutex_lock(timeout_mutex); } +static void process_keepalive_queue(apr_time_t timeout_time) +{ + apr_uint32_t total = apr_atomic_read32(keepalive_q->total); + if (total) { + /* If all workers are busy, we kill older keep-alive connections so + * that they may connect to another process. + */ + if (!timeout_time) { + ap_log_error(APLOG_MARK, APLOG_TRACE1, 0, ap_server_conf, + "All workers are busy or dying, will close " + "%d keep-alive connections", (int)total); + } + process_timeout_queue(keepalive_q, timeout_time, + start_lingering_close_nonblocking); + } +} + static void * APR_THREAD_FUNC listener_thread(apr_thread_t * thd, void *dummy) { apr_status_t rc; @@ -1834,7 +1851,6 @@ static void * APR_THREAD_FUNC listener_thread(apr_thread_t * thd, void *dummy) apr_interval_time_t timeout_interval; apr_time_t now, timeout_time; int workers_were_busy = 0; - int keepalives; if (listener_may_exit) { close_listeners(process_slot, &closed); @@ -2185,8 +2201,12 @@ static void * APR_THREAD_FUNC listener_thread(apr_thread_t * thd, void *dummy) queues_next_expiry = 0; /* Step 1: keepalive timeouts */ - process_timeout_queue(keepalive_q, timeout_time, - start_lingering_close_nonblocking); + if (workers_were_busy || dying) { + process_keepalive_queue(0); /* kill'em all \m/ */ + } + else { + process_keepalive_queue(timeout_time); + } /* Step 2: write completion timeouts */ process_timeout_queue(write_completion_q, timeout_time, start_lingering_close_nonblocking); @@ -2205,20 +2225,11 @@ static void * APR_THREAD_FUNC listener_thread(apr_thread_t * thd, void *dummy) ps->suspended = apr_atomic_read32(&suspended_count); ps->lingering_close = apr_atomic_read32(&lingering_count); } - else if ((workers_were_busy || dying) - && (keepalives = apr_atomic_read32(keepalive_q->total))) { - /* If all workers are busy, we kill older keep-alive connections so - * that they may connect to another process. - */ - ap_log_error(APLOG_MARK, APLOG_TRACE1, 0, ap_server_conf, - "All workers are %s, will close %d keep-alive " - "connections", dying ? "dying" : "busy", - keepalives); + else if (workers_were_busy || dying) { apr_thread_mutex_lock(timeout_mutex); - process_timeout_queue(keepalive_q, 0, - start_lingering_close_nonblocking); + process_keepalive_queue(0); /* kill'em all \m/ */ apr_thread_mutex_unlock(timeout_mutex); - ps->keep_alive = apr_atomic_read32(keepalive_q->total); + ps->keep_alive = 0; } if (listeners_disabled && !workers_were_busy -- cgit v1.2.1