From: Stefan Eissing Date: Fri, 10 Sep 2021 08:14:48 +0000 (+0000) Subject: * mod_http2: when a server is restarted gracefully, any idle h2 worker X-Git-Tag: 2.5.0-alpha2-ci-test-only~817 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=5057dc6a8e77b7a132e4ea2c2381bf9fbfefec8e;p=thirdparty%2Fapache%2Fhttpd.git * mod_http2: when a server is restarted gracefully, any idle h2 worker threads are shut down immediately. [Stefan Eissing] git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1893214 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/changes-entries/http2_graceful.txt b/changes-entries/http2_graceful.txt new file mode 100644 index 00000000000..dc57195252f --- /dev/null +++ b/changes-entries/http2_graceful.txt @@ -0,0 +1,4 @@ + * mod_http2: when a server is restarted gracefully, any idle h2 worker + threads are shut down immediately. [Stefan Eissing] + + diff --git a/modules/http2/h2_conn.c b/modules/http2/h2_conn.c index 7d539c540c8..018d5819a78 100644 --- a/modules/http2/h2_conn.c +++ b/modules/http2/h2_conn.c @@ -148,6 +148,13 @@ apr_status_t h2_conn_child_init(apr_pool_t *pool, server_rec *s) return status; } +void h2_conn_child_stopping(apr_pool_t *pool, int graceful) +{ + if (workers && graceful) { + h2_workers_graceful_shutdown(workers); + } +} + h2_mpm_type_t h2_conn_mpm_type(void) { check_modules(0); diff --git a/modules/http2/h2_conn.h b/modules/http2/h2_conn.h index 3b8b33e3994..de868cfa579 100644 --- a/modules/http2/h2_conn.h +++ b/modules/http2/h2_conn.h @@ -45,12 +45,17 @@ apr_status_t h2_conn_run(conn_rec *c); */ apr_status_t h2_conn_pre_close(struct h2_ctx *ctx, conn_rec *c); -/* Initialize this child process for h2 connection work, +/** + * Initialize this child process for h2 connection work, * to be called once during child init before multi processing * starts. */ apr_status_t h2_conn_child_init(apr_pool_t *pool, server_rec *s); +/** + * Child is about to be stopped, release unused resources + */ +void h2_conn_child_stopping(apr_pool_t *pool, int graceful); typedef enum { H2_MPM_UNKNOWN, diff --git a/modules/http2/h2_session.c b/modules/http2/h2_session.c index 453a98fd36c..3284aa2ff64 100644 --- a/modules/http2/h2_session.c +++ b/modules/http2/h2_session.c @@ -1912,7 +1912,9 @@ static void h2_session_ev_mpm_stopping(h2_session *session, int arg, const char break; default: h2_session_shutdown_notice(session); +#if !AP_MODULE_MAGIC_AT_LEAST(20120211, 110) h2_workers_graceful_shutdown(session->workers); +#endif break; } } diff --git a/modules/http2/h2_task.c b/modules/http2/h2_task.c index 2ac6ea4735c..5b32656a912 100644 --- a/modules/http2/h2_task.c +++ b/modules/http2/h2_task.c @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - + #include #include diff --git a/modules/http2/h2_util.c b/modules/http2/h2_util.c index c00a31c5ab1..9b2b3de9682 100644 --- a/modules/http2/h2_util.c +++ b/modules/http2/h2_util.c @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - + #include #include #include diff --git a/modules/http2/h2_version.h b/modules/http2/h2_version.h index 785a172386f..664e63a0727 100644 --- a/modules/http2/h2_version.h +++ b/modules/http2/h2_version.h @@ -27,7 +27,7 @@ * @macro * Version number of the http2 module as c string */ -#define MOD_HTTP2_VERSION "1.15.22" +#define MOD_HTTP2_VERSION "1.15.23" /** * @macro @@ -35,7 +35,7 @@ * release. This is a 24 bit number with 8 bits for major number, 8 bits * for minor and 8 bits for patch. Version 1.2.3 becomes 0x010203. */ -#define MOD_HTTP2_VERSION_NUM 0x010f16 +#define MOD_HTTP2_VERSION_NUM 0x010f17 #endif /* mod_h2_h2_version_h */ diff --git a/modules/http2/h2_workers.c b/modules/http2/h2_workers.c index b3eca4285c3..ceed4c6d5e1 100644 --- a/modules/http2/h2_workers.c +++ b/modules/http2/h2_workers.c @@ -480,6 +480,8 @@ apr_status_t h2_workers_unregister(h2_workers *workers, struct h2_mplx *m) void h2_workers_graceful_shutdown(h2_workers *workers) { workers->shutdown = 1; + workers->min_workers = 1; + workers->max_idle_duration = apr_time_from_sec(1); h2_fifo_term(workers->mplxs); wake_non_essential_workers(workers); } diff --git a/modules/http2/h2_workers.h b/modules/http2/h2_workers.h index cc310c9b75b..2aa3b3a3b31 100644 --- a/modules/http2/h2_workers.h +++ b/modules/http2/h2_workers.h @@ -38,9 +38,9 @@ struct h2_workers { apr_pool_t *pool; int next_worker_id; - apr_uint32_t min_workers; apr_uint32_t max_workers; - apr_interval_time_t max_idle_duration; + volatile apr_uint32_t min_workers; /* is changed during graceful shutdown */ + volatile apr_interval_time_t max_idle_duration; /* is changed during graceful shutdown */ volatile int aborted; volatile int shutdown; diff --git a/modules/http2/mod_http2.c b/modules/http2/mod_http2.c index 24f15857251..3f2a61fc3ed 100644 --- a/modules/http2/mod_http2.c +++ b/modules/http2/mod_http2.c @@ -24,6 +24,7 @@ #include #include #include +#include #include "mod_http2.h" @@ -228,7 +229,9 @@ static void h2_hooks(apr_pool_t *pool) /* Run once after a child process has been created. */ ap_hook_child_init(h2_child_init, NULL, NULL, APR_HOOK_MIDDLE); - +#if AP_MODULE_MAGIC_AT_LEAST(20120211, 110) + ap_hook_child_stopping(h2_conn_child_stopping, NULL, NULL, APR_HOOK_MIDDLE); +#endif h2_h2_register_hooks(); h2_switch_register_hooks(); h2_task_register_hooks();