From d0bf247419899d40ccd30f47cb343e364050a9a5 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Sat, 4 Jun 2016 12:43:17 +0900 Subject: [PATCH] nghttpx: Refactor graceful shutdown in Http2Upstream Instead of using bool flag, just stop prepare watcher. --- src/shrpx_http2_upstream.cc | 32 ++++++++++++++++---------------- src/shrpx_http2_upstream.h | 1 - 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/src/shrpx_http2_upstream.cc b/src/shrpx_http2_upstream.cc index 8f9e4645..27b0f718 100644 --- a/src/shrpx_http2_upstream.cc +++ b/src/shrpx_http2_upstream.cc @@ -787,23 +787,25 @@ void Http2Upstream::submit_goaway() { void Http2Upstream::check_shutdown() { int rv; - if (shutdown_handled_) { - return; - } auto worker = handler_->get_worker(); - if (worker->get_graceful_shutdown()) { - shutdown_handled_ = true; - rv = nghttp2_submit_shutdown_notice(session_); - if (rv != 0) { - ULOG(FATAL, this) << "nghttp2_submit_shutdown_notice() failed: " - << nghttp2_strerror(rv); - return; - } - handler_->signal_write(); - ev_timer_start(handler_->get_loop(), &shutdown_timer_); + if (!worker->get_graceful_shutdown()) { + return; } + + ev_prepare_stop(handler_->get_loop(), &prep_); + + rv = nghttp2_submit_shutdown_notice(session_); + if (rv != 0) { + ULOG(FATAL, this) << "nghttp2_submit_shutdown_notice() failed: " + << nghttp2_strerror(rv); + return; + } + + handler_->signal_write(); + + ev_timer_start(handler_->get_loop(), &shutdown_timer_); } nghttp2_session_callbacks *create_http2_upstream_callbacks() { @@ -870,9 +872,7 @@ Http2Upstream::Http2Upstream(ClientHandler *handler) downstream_queue_(downstream_queue_size(handler->get_worker()), !get_config()->http2_proxy), handler_(handler), - session_(nullptr), - shutdown_handled_(false) { - + session_(nullptr) { int rv; auto &http2conf = get_config()->http2; diff --git a/src/shrpx_http2_upstream.h b/src/shrpx_http2_upstream.h index 1908a504..80585031 100644 --- a/src/shrpx_http2_upstream.h +++ b/src/shrpx_http2_upstream.h @@ -132,7 +132,6 @@ private: ClientHandler *handler_; nghttp2_session *session_; bool flow_control_; - bool shutdown_handled_; }; nghttp2_session_callbacks *create_http2_upstream_callbacks();