@@ -188,6 +188,7 @@ static int num_listensocks = 0;
188188static apr_int32_t conns_this_child ; /* MaxConnectionsPerChild, only access
189189 in listener thread */
190190static apr_uint32_t connection_count = 0 ; /* Number of open connections */
191+ static apr_uint32_t extra_connection_count = 0 ; /* Number of open connections that the MPM does not own */
191192static apr_uint32_t lingering_count = 0 ; /* Number of connections in lingering close */
192193static apr_uint32_t suspended_count = 0 ; /* Number of suspended connections */
193194static apr_uint32_t clogged_count = 0 ; /* Number of threads processing ssl conns */
@@ -873,16 +874,39 @@ static apr_status_t decrement_connection_count(void *cs_)
873874
874875static void ap_mpm_note_extra_connection_added (void )
875876{
876- apr_atomic_inc32 (& connection_count );
877+ apr_atomic_inc32 (& extra_connection_count );
877878}
878879
879880static void ap_mpm_note_extra_connection_removed (void )
880881{
881- int is_last_connection = !apr_atomic_dec32 (& connection_count );
882+ apr_atomic_dec32 (& extra_connection_count );
883+ }
882884
883- /* Wake a listener blocked waiting for connection_count to drain. */
884- if (listener_is_wakeable && is_last_connection && listener_may_exit ) {
885- apr_pollset_wakeup (event_pollset );
885+ static void wait_for_extra_connections (void )
886+ {
887+ apr_uint32_t count = apr_atomic_read32 (& extra_connection_count );
888+ apr_time_t graceful , timeout , deadline ;
889+
890+ if (count == 0 ) {
891+ return ;
892+ }
893+
894+ graceful = apr_time_from_sec (ap_graceful_shutdown_timeout );
895+ timeout = (graceful > ap_server_conf -> timeout ) ? graceful : ap_server_conf -> timeout ;
896+ deadline = apr_time_now () + timeout ;
897+
898+ do {
899+ apr_sleep (apr_time_from_msec (100 ));
900+ count = apr_atomic_read32 (& extra_connection_count );
901+ } while (count > 0 && apr_time_now () < deadline );
902+
903+ if (count > 0 ) {
904+ ap_log_error (APLOG_MARK , APLOG_WARNING , 0 , ap_server_conf ,
905+ APLOGNO (10619 )
906+ "Child: %u connection(s) noted by modules did not "
907+ "finish within %" APR_TIME_T_FMT " seconds, "
908+ "exiting anyway" ,
909+ count , apr_time_sec (timeout ));
886910 }
887911}
888912
@@ -3154,6 +3178,10 @@ static void child_main(int child_num_arg, int child_bucket)
31543178 rv == AP_MPM_PODX_GRACEFUL ? "graceful" : "ungraceful" );
31553179 }
31563180
3181+ if (terminate_mode == ST_GRACEFUL ) {
3182+ wait_for_extra_connections ();
3183+ }
3184+
31573185 free (threads );
31583186
31593187 clean_child_exit (resource_shortage ? APEXIT_CHILDSICK : 0 );
0 commit comments