From 6b38f7e0d215256e1e59136b474e98a20a14c6d4 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Fri, 4 Sep 2015 22:21:10 +0900 Subject: [PATCH] nghttpx: Fix crash with multi workers and QUIT signal --- src/shrpx_connection_handler.cc | 8 ++++++++ src/shrpx_connection_handler.h | 2 ++ src/shrpx_worker.cc | 1 - 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/shrpx_connection_handler.cc b/src/shrpx_connection_handler.cc index 8b493a55..3d9cf070 100644 --- a/src/shrpx_connection_handler.cc +++ b/src/shrpx_connection_handler.cc @@ -130,6 +130,13 @@ ConnectionHandler::~ConnectionHandler() { } SSL_CTX_free(ssl_ctx); } + + // Free workers before destroying ev_loop + workers_.clear(); + + for (auto loop : worker_loops_) { + ev_loop_destroy(loop); + } } void ConnectionHandler::set_ticket_keys_to_worker( @@ -181,6 +188,7 @@ void ConnectionHandler::create_worker_thread(size_t num) { ticket_keys_); worker->run_async(); workers_.push_back(std::move(worker)); + worker_loops_.push_back(loop); if (LOG_ENABLED(INFO)) { LLOG(INFO, this) << "Created thread #" << workers_.size() - 1; diff --git a/src/shrpx_connection_handler.h b/src/shrpx_connection_handler.h index d46f059c..44fe5955 100644 --- a/src/shrpx_connection_handler.h +++ b/src/shrpx_connection_handler.h @@ -127,6 +127,8 @@ private: // Stores all SSL_CTX objects. std::vector all_ssl_ctx_; OCSPUpdateContext ocsp_; + // ev_loop for each worker + std::vector worker_loops_; // Worker instances when multi threaded mode (-nN, N >= 2) is used. std::vector> workers_; // Worker instance used when single threaded mode (-n1) is used. diff --git a/src/shrpx_worker.cc b/src/shrpx_worker.cc index 2241f979..58bfb633 100644 --- a/src/shrpx_worker.cc +++ b/src/shrpx_worker.cc @@ -101,7 +101,6 @@ Worker::Worker(struct ev_loop *loop, SSL_CTX *sv_ssl_ctx, SSL_CTX *cl_ssl_ctx, Worker::~Worker() { ev_async_stop(loop_, &w_); ev_timer_stop(loop_, &mcpool_clear_timer_); - ev_loop_destroy(loop_); } void Worker::schedule_clear_mcpool() {