Skip to content

Commit

Permalink
* when ongoing sessions detect that the process shuts down (for exam…
Browse files Browse the repository at this point in the history
…ple due to a

   graceful restart), they now cause idle h2 workers to terminate early.
   This hopefully addresses #212.
  • Loading branch information
Stefan Eissing committed Jun 21, 2021
1 parent b4aa03b commit 2e536e3
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 3 deletions.
4 changes: 4 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
* when ongoing sessions detect that the process shuts down (for example due to a
graceful restart), they now cause idle h2 workers to terminate early.
This hopefully addresses #212.

v1.15.20
--------------------------------------------------------------------------------
* requires apache httpd 2.4.48
Expand Down
1 change: 1 addition & 0 deletions mod_http2/h2_session.c
Original file line number Diff line number Diff line change
Expand Up @@ -1908,6 +1908,7 @@ static void h2_session_ev_mpm_stopping(h2_session *session, int arg, const char
break;
default:
h2_session_shutdown_notice(session);
h2_workers_graceful_shutdown(session->workers);
break;
}
}
Expand Down
17 changes: 14 additions & 3 deletions mod_http2/h2_workers.c
Original file line number Diff line number Diff line change
Expand Up @@ -257,11 +257,10 @@ static void* APR_THREAD_FUNC slot_run(apr_thread_t *thread, void *wctx)
return NULL;
}

static apr_status_t workers_pool_cleanup(void *data)
static void workers_abort_idle(h2_workers *workers)
{
h2_workers *workers = data;
h2_slot *slot;

workers->aborted = 1;
h2_fifo_term(workers->mplxs);

Expand All @@ -271,6 +270,13 @@ static apr_status_t workers_pool_cleanup(void *data)
apr_thread_cond_signal(slot->not_idle);
apr_thread_mutex_unlock(slot->lock);
}
}

static apr_status_t workers_pool_cleanup(void *data)
{
h2_workers *workers = data;

workers_abort_idle(workers);

/* wait for all the workers to become zombies and join them */
apr_thread_mutex_lock(workers->lock);
Expand Down Expand Up @@ -396,3 +402,8 @@ apr_status_t h2_workers_unregister(h2_workers *workers, struct h2_mplx *m)
{
return h2_fifo_remove(workers->mplxs, m);
}

void h2_workers_graceful_shutdown(h2_workers *workers)
{
workers_abort_idle(workers);
}
5 changes: 5 additions & 0 deletions mod_http2/h2_workers.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,9 @@ apr_status_t h2_workers_register(h2_workers *workers, struct h2_mplx *m);
*/
apr_status_t h2_workers_unregister(h2_workers *workers, struct h2_mplx *m);

/**
* Shut down processing gracefully by terminating all idle workers.
*/
void h2_workers_graceful_shutdown(h2_workers *workers);

#endif /* defined(__mod_h2__h2_workers__) */

0 comments on commit 2e536e3

Please sign in to comment.