From ca87b45fe46ae6a9d1697c59535ef91a86d695f8 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Fri, 27 Jun 2014 22:34:54 +0900 Subject: [PATCH] nghttpx: Don't fail backend connection if one of backend request fails --- src/shrpx_http2_session.cc | 18 ++++++++++++++++-- src/shrpx_http2_upstream.cc | 14 ++++++++++++++ src/shrpx_http2_upstream.h | 2 ++ src/shrpx_https_upstream.cc | 6 ++++++ src/shrpx_https_upstream.h | 3 ++- src/shrpx_spdy_upstream.cc | 14 ++++++++++++++ src/shrpx_spdy_upstream.h | 2 ++ src/shrpx_upstream.h | 2 ++ 8 files changed, 58 insertions(+), 3 deletions(-) diff --git a/src/shrpx_http2_session.cc b/src/shrpx_http2_session.cc index b7fda983..3de70cc4 100644 --- a/src/shrpx_http2_session.cc +++ b/src/shrpx_http2_session.cc @@ -1291,9 +1291,23 @@ int Http2Session::on_connect() // submit pending request for(auto dconn : dconns_) { - if(dconn->push_request_headers() != 0) { - return -1; + if(dconn->push_request_headers() == 0) { + continue; } + + if(LOG_ENABLED(INFO)) { + SSLOG(INFO, this) << "backend request failed"; + } + + auto downstream = dconn->get_downstream(); + + if(!downstream) { + continue; + } + + auto upstream = downstream->get_upstream(); + + upstream->on_downstream_abort_request(downstream, 400); } return 0; } diff --git a/src/shrpx_http2_upstream.cc b/src/shrpx_http2_upstream.cc index 284f6239..43fd1fc2 100644 --- a/src/shrpx_http2_upstream.cc +++ b/src/shrpx_http2_upstream.cc @@ -1216,4 +1216,18 @@ int Http2Upstream::resume_read(IOCtrlReason reason, Downstream *downstream) return send(); } +int Http2Upstream::on_downstream_abort_request(Downstream *downstream, + unsigned int status_code) +{ + int rv; + + rv = error_reply(downstream, status_code); + + if(rv != 0) { + return -1; + } + + return send(); +} + } // namespace shrpx diff --git a/src/shrpx_http2_upstream.h b/src/shrpx_http2_upstream.h index 02eebd18..4261c3ac 100644 --- a/src/shrpx_http2_upstream.h +++ b/src/shrpx_http2_upstream.h @@ -46,6 +46,8 @@ public: virtual int on_read(); virtual int on_write(); virtual int on_event(); + virtual int on_downstream_abort_request(Downstream *downstream, + unsigned int status_code); int send(); virtual ClientHandler* get_client_handler() const; virtual bufferevent_data_cb get_downstream_readcb(); diff --git a/src/shrpx_https_upstream.cc b/src/shrpx_https_upstream.cc index 5ce8f244..6864ca76 100644 --- a/src/shrpx_https_upstream.cc +++ b/src/shrpx_https_upstream.cc @@ -887,4 +887,10 @@ int HttpsUpstream::on_downstream_body_complete(Downstream *downstream) return 0; } +int HttpsUpstream::on_downstream_abort_request(Downstream *downstream, + unsigned int status_code) +{ + return error_reply(status_code); +} + } // namespace shrpx diff --git a/src/shrpx_https_upstream.h b/src/shrpx_https_upstream.h index c99eff10..466334ef 100644 --- a/src/shrpx_https_upstream.h +++ b/src/shrpx_https_upstream.h @@ -44,7 +44,8 @@ public: virtual int on_read(); virtual int on_write(); virtual int on_event(); - //int send(); + virtual int on_downstream_abort_request(Downstream *downstream, + unsigned int status_code); virtual ClientHandler* get_client_handler() const; virtual bufferevent_data_cb get_downstream_readcb(); virtual bufferevent_data_cb get_downstream_writecb(); diff --git a/src/shrpx_spdy_upstream.cc b/src/shrpx_spdy_upstream.cc index 2694ea95..fb517968 100644 --- a/src/shrpx_spdy_upstream.cc +++ b/src/shrpx_spdy_upstream.cc @@ -1030,4 +1030,18 @@ int SpdyUpstream::resume_read(IOCtrlReason reason, Downstream *downstream) return send(); } +int SpdyUpstream::on_downstream_abort_request(Downstream *downstream, + unsigned int status_code) +{ + int rv; + + rv = error_reply(downstream, status_code); + + if(rv != 0) { + return -1; + } + + return send(); +} + } // namespace shrpx diff --git a/src/shrpx_spdy_upstream.h b/src/shrpx_spdy_upstream.h index 06b0d6f8..89e1da71 100644 --- a/src/shrpx_spdy_upstream.h +++ b/src/shrpx_spdy_upstream.h @@ -44,6 +44,8 @@ public: virtual int on_read(); virtual int on_write(); virtual int on_event(); + virtual int on_downstream_abort_request(Downstream *downstream, + unsigned int status_code); int send(); virtual ClientHandler* get_client_handler() const; virtual bufferevent_data_cb get_downstream_readcb(); diff --git a/src/shrpx_upstream.h b/src/shrpx_upstream.h index 792daa36..d48b14b2 100644 --- a/src/shrpx_upstream.h +++ b/src/shrpx_upstream.h @@ -42,6 +42,8 @@ public: virtual int on_read() = 0; virtual int on_write() = 0; virtual int on_event() = 0; + virtual int on_downstream_abort_request(Downstream *downstream, + unsigned int status_code) = 0; virtual bufferevent_data_cb get_downstream_readcb() = 0; virtual bufferevent_data_cb get_downstream_writecb() = 0; virtual bufferevent_event_cb get_downstream_eventcb() = 0;