From 50c4aa061fef55d186cd528fa32c17bb64e8fa55 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Fri, 20 Feb 2015 19:23:52 +0900 Subject: [PATCH] nghttpx: Response with 503 when re-submission to backend failed --- src/shrpx_http2_upstream.cc | 17 ++++++++++------- src/shrpx_https_upstream.cc | 14 ++++++++++---- src/shrpx_spdy_upstream.cc | 17 ++++++++++------- 3 files changed, 30 insertions(+), 18 deletions(-) diff --git a/src/shrpx_http2_upstream.cc b/src/shrpx_http2_upstream.cc index 794beaec..ccd40fde 100644 --- a/src/shrpx_http2_upstream.cc +++ b/src/shrpx_http2_upstream.cc @@ -1420,10 +1420,7 @@ int Http2Upstream::on_downstream_reset(bool no_retry) { downstream->add_retry(); if (no_retry || downstream->no_more_retry()) { - if (on_downstream_abort_request(downstream, 503) != 0) { - return -1; - } - continue; + goto fail; } // downstream connection is clean; we can retry with new @@ -1432,10 +1429,16 @@ int Http2Upstream::on_downstream_reset(bool no_retry) { rv = downstream->attach_downstream_connection( handler_->get_downstream_connection()); if (rv != 0) { - rst_stream(downstream, NGHTTP2_INTERNAL_ERROR); - downstream->pop_downstream_connection(); - continue; + goto fail; } + + continue; + + fail: + if (on_downstream_abort_request(downstream, 503) != 0) { + return -1; + } + downstream->pop_downstream_connection(); } handler_->signal_write(); diff --git a/src/shrpx_https_upstream.cc b/src/shrpx_https_upstream.cc index 15e418ce..63a2fbf9 100644 --- a/src/shrpx_https_upstream.cc +++ b/src/shrpx_https_upstream.cc @@ -854,17 +854,23 @@ int HttpsUpstream::on_downstream_reset(bool no_retry) { downstream_->add_retry(); if (no_retry || downstream_->no_more_retry()) { - if (on_downstream_abort_request(downstream_.get(), 503) != 0) { - return -1; - } - return 0; + goto fail; } rv = downstream_->attach_downstream_connection( handler_->get_downstream_connection()); if (rv != 0) { + goto fail; + } + + return 0; + +fail: + if (on_downstream_abort_request(downstream_.get(), 503) != 0) { return -1; } + downstream_->pop_downstream_connection(); + return 0; } diff --git a/src/shrpx_spdy_upstream.cc b/src/shrpx_spdy_upstream.cc index a39d8f8b..6a2b95ad 100644 --- a/src/shrpx_spdy_upstream.cc +++ b/src/shrpx_spdy_upstream.cc @@ -1052,10 +1052,7 @@ int SpdyUpstream::on_downstream_reset(bool no_retry) { downstream->add_retry(); if (no_retry || downstream->no_more_retry()) { - if (on_downstream_abort_request(downstream, 503) != 0) { - return -1; - } - return 0; + goto fail; } // downstream connection is clean; we can retry with new @@ -1064,10 +1061,16 @@ int SpdyUpstream::on_downstream_reset(bool no_retry) { rv = downstream->attach_downstream_connection( handler_->get_downstream_connection()); if (rv != 0) { - rst_stream(downstream, SPDYLAY_INTERNAL_ERROR); - downstream->pop_downstream_connection(); - continue; + goto fail; } + + continue; + + fail: + if (on_downstream_abort_request(downstream, 503) != 0) { + return -1; + } + downstream->pop_downstream_connection(); } handler_->signal_write();