From 185ebd7b794f241d15130d7f6884d850ce4f402d Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Sun, 1 Mar 2015 10:11:45 +0900 Subject: [PATCH] nghttpx: Fix crash when upgrading HTTP/2 failed --- src/shrpx_client_handler.cc | 1 + src/shrpx_http2_upstream.cc | 6 ++++-- src/shrpx_https_upstream.cc | 10 ++++------ 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/shrpx_client_handler.cc b/src/shrpx_client_handler.cc index 305f17db..9ca38690 100644 --- a/src/shrpx_client_handler.cc +++ b/src/shrpx_client_handler.cc @@ -662,6 +662,7 @@ int ClientHandler::perform_http2_upgrade(HttpsUpstream *http) { "Upgrade: " NGHTTP2_CLEARTEXT_PROTO_VERSION_ID "\r\n" "\r\n"; wb_.write(res, sizeof(res) - 1); + signal_write(); return 0; } diff --git a/src/shrpx_http2_upstream.cc b/src/shrpx_http2_upstream.cc index f5cb3d85..5306403d 100644 --- a/src/shrpx_http2_upstream.cc +++ b/src/shrpx_http2_upstream.cc @@ -116,8 +116,10 @@ int Http2Upstream::upgrade_upstream(HttpsUpstream *http) { session_, reinterpret_cast(settings_payload.c_str()), settings_payload.size(), nullptr); if (rv != 0) { - ULOG(WARN, this) << "nghttp2_session_upgrade() returned error: " - << nghttp2_strerror(rv); + if (LOG_ENABLED(INFO)) { + ULOG(INFO, this) << "nghttp2_session_upgrade() returned error: " + << nghttp2_strerror(rv); + } return -1; } pre_upstream_.reset(http); diff --git a/src/shrpx_https_upstream.cc b/src/shrpx_https_upstream.cc index 7a7d1e46..302b928f 100644 --- a/src/shrpx_https_upstream.cc +++ b/src/shrpx_https_upstream.cc @@ -234,13 +234,11 @@ int htp_msg_completecb(http_parser *htp) { } if (handler->get_http2_upgrade_allowed() && - downstream->get_http2_upgrade_request()) { - - if (handler->perform_http2_upgrade(upstream) != 0) { - return -1; + downstream->get_http2_upgrade_request() && + handler->perform_http2_upgrade(upstream) != 0) { + if (LOG_ENABLED(INFO)) { + ULOG(INFO, upstream) << "HTTP Upgrade to HTTP/2 failed"; } - - handler->signal_write(); } // Stop further processing to complete this request