Skip to content

Commit 8d6202e

Browse files
committed
consistency sweep
1 parent fbc56bf commit 8d6202e

6 files changed

Lines changed: 36 additions & 26 deletions

File tree

CHANGES

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
-*- coding: utf-8 -*-
22
Changes with Apache 2.5.1
33

4-
*) mpm_event, mpm_worker, mpm_winnt, mpm_prefork: Add optional hooks to
5-
account for connections managed outside the MPM accept loop (e.g., UDP).
4+
*) mpm_event, mpm_worker, mpm_winnt, mpm_prefork: Add the optional functions
5+
ap_mpm_note_extra_connection_added() and
6+
ap_mpm_note_extra_connection_removed() to account for connections managed
7+
outside the MPM accept loop (e.g., UDP). On graceful stop a child waits
8+
for those connections no longer than max(Timeout,
9+
GracefulShutdownTimeout), then warns and exits.
610
[Tarek Ibrahim <tareki@pulsarxtech.com> <t1br4h1m@gmail.com>]
711

812
* mod_ssl: Add support for OpenSSL provider based certificate

include/ap_mmn.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -737,7 +737,9 @@
737737
* 20211221.29 (2.5.1-dev) Add ap_set_time_process_request() to scoreboard.h
738738
* 20211221.30 (2.5.1-dev) Add ap_stat_check() to httpd.h
739739
* 20211221.31 (2.5.1-dev) Add ap_*_timingsafe() to httpd.h
740-
* 20211221.32 (2.5.1-dev) Add optional hooks for MPM to accept UDP conns.
740+
* 20211221.32 (2.5.1-dev) Add the optional functions ap_mpm_note_extra_
741+
* connection_added() and ap_mpm_note_extra_
742+
* connection_removed() to mpm_common.h
741743
*/
742744

743745
#define MODULE_MAGIC_COOKIE 0x41503235UL /* "AP25" */

include/mpm_common.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,12 @@ void mpm_common_pre_config(apr_pool_t *pconf);
571571
* Call ap_mpm_note_extra_connection_added() when such a connection starts,
572572
* and ap_mpm_note_extra_connection_removed() when it ends. These functions
573573
* may be NULL if the active MPM does not implement them.
574+
*
575+
* A module using them is expected to notice that the child is stopping (e.g.
576+
* with the child_stopping hook) and to end the connections it noted in a
577+
* timely manner, gracefully or not. The MPM waits for them no longer than
578+
* max(Timeout, GracefulShutdownTimeout), then logs a warning and exits
579+
* anyway, possibly cutting those connections short.
574580
*/
575581
APR_DECLARE_OPTIONAL_FN(void, ap_mpm_note_extra_connection_added, (void));
576582
APR_DECLARE_OPTIONAL_FN(void, ap_mpm_note_extra_connection_removed, (void));

server/mpm/prefork/prefork.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@
9090

9191
/* config globals */
9292

93-
static apr_uint32_t connection_count = 0; /* Number of open connections */
93+
static apr_uint32_t extra_connection_count = 0; /* Number of open connections that the MPM does not own */
9494
static int ap_daemons_to_start=0;
9595
static int ap_daemons_min_free=0;
9696
static int ap_daemons_max_free=0;
@@ -219,9 +219,19 @@ static void prefork_note_child_started(int slot, pid_t pid)
219219
ap_run_child_status(ap_server_conf, pid, gen, slot, MPM_CHILD_STARTED);
220220
}
221221

222+
static void ap_mpm_note_extra_connection_added(void)
223+
{
224+
apr_atomic_inc32(&extra_connection_count);
225+
}
226+
227+
static void ap_mpm_note_extra_connection_removed(void)
228+
{
229+
apr_atomic_dec32(&extra_connection_count);
230+
}
231+
222232
static void wait_for_extra_connections(void)
223233
{
224-
apr_uint32_t count = apr_atomic_read32(&connection_count);
234+
apr_uint32_t count = apr_atomic_read32(&extra_connection_count);
225235
apr_time_t graceful, timeout, deadline;
226236

227237
if (count == 0) {
@@ -234,7 +244,7 @@ static void wait_for_extra_connections(void)
234244

235245
do {
236246
apr_sleep(apr_time_from_msec(100));
237-
count = apr_atomic_read32(&connection_count);
247+
count = apr_atomic_read32(&extra_connection_count);
238248
} while (count > 0 && apr_time_now() < deadline);
239249

240250
if (count > 0) {
@@ -413,16 +423,6 @@ static void just_die(int sig)
413423
/* volatile because it's updated from a signal handler */
414424
static int volatile die_now = 0;
415425

416-
static void ap_mpm_note_extra_connection_added(void)
417-
{
418-
apr_atomic_inc32(&connection_count);
419-
}
420-
421-
static void ap_mpm_note_extra_connection_removed(void)
422-
{
423-
apr_atomic_dec32(&connection_count);
424-
}
425-
426426
static void stop_listening(int sig)
427427
{
428428
retained->mpm->mpm_state = AP_MPMQ_STOPPING;

server/mpm/winnt/child.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,10 @@ static apr_thread_mutex_t *ctxpool_lock;
131131
static winnt_conn_ctx_t *ctxpool_head = NULL;
132132
static apr_uint32_t num_completion_contexts = 0;
133133
static apr_uint32_t max_num_completion_contexts = 0;
134-
static apr_uint32_t extra_connection_count = 0;
134+
static apr_uint32_t extra_connection_count = 0; /* Number of open connections that the MPM does not own */
135135
static HANDLE ThreadDispatchIOCP = NULL;
136136
static HANDLE ctxpool_wait_event = NULL;
137137

138-
/* Connections a module accepted itself, which the worker threads do not serve. */
139138
void ap_mpm_note_extra_connection_added(void)
140139
{
141140
apr_atomic_inc32(&extra_connection_count);
@@ -149,16 +148,15 @@ void ap_mpm_note_extra_connection_removed(void)
149148
static void wait_for_extra_connections(void)
150149
{
151150
apr_uint32_t count = apr_atomic_read32(&extra_connection_count);
152-
apr_time_t graceful, timeout;
153-
int time_remains;
151+
apr_time_t graceful, timeout, time_remains;
154152

155153
if (count == 0) {
156154
return;
157155
}
158156

159157
graceful = apr_time_from_sec(ap_graceful_shutdown_timeout);
160158
timeout = (graceful > ap_server_conf->timeout) ? graceful : ap_server_conf->timeout;
161-
time_remains = (int)(timeout / APR_TIME_C(1000));
159+
time_remains = timeout / APR_TIME_C(1000);
162160

163161
do {
164162
Sleep(100);

server/mpm/worker/worker.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@
118118
* Actual definitions of config globals
119119
*/
120120

121-
static apr_uint32_t connection_count = 0; /* Number of open connections */
121+
static apr_uint32_t extra_connection_count = 0; /* Number of open connections that the MPM does not own */
122122
static int threads_per_child = 0; /* Worker threads per child */
123123
static int ap_daemons_to_start = 0;
124124
static int min_spare_threads = 0;
@@ -515,17 +515,17 @@ static void check_infinite_requests(void)
515515

516516
static void ap_mpm_note_extra_connection_added(void)
517517
{
518-
apr_atomic_inc32(&connection_count);
518+
apr_atomic_inc32(&extra_connection_count);
519519
}
520520

521521
static void ap_mpm_note_extra_connection_removed(void)
522522
{
523-
apr_atomic_dec32(&connection_count);
523+
apr_atomic_dec32(&extra_connection_count);
524524
}
525525

526526
static void wait_for_extra_connections(void)
527527
{
528-
apr_uint32_t count = apr_atomic_read32(&connection_count);
528+
apr_uint32_t count = apr_atomic_read32(&extra_connection_count);
529529
apr_time_t graceful, timeout, deadline;
530530

531531
if (count == 0) {
@@ -538,7 +538,7 @@ static void wait_for_extra_connections(void)
538538

539539
do {
540540
apr_sleep(apr_time_from_msec(100));
541-
count = apr_atomic_read32(&connection_count);
541+
count = apr_atomic_read32(&extra_connection_count);
542542
} while (count > 0 && apr_time_now() < deadline);
543543

544544
if (count > 0) {

0 commit comments

Comments
 (0)