From f8933fe50468413eb149df7e331e7335400f1649 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Sat, 7 Sep 2019 18:20:24 +0900 Subject: [PATCH] nghttpx: Reconnect h1 backend if it lost connection before sending headers This is the second attempt. The first attempt was 8a59ce6d37471ec7a437d4700cabd98c55115b1e and it failed. --- src/shrpx_http2_upstream.cc | 5 ++++- src/shrpx_http_downstream_connection.cc | 21 ++++++++++++++------- src/shrpx_https_upstream.cc | 5 ++++- 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/src/shrpx_http2_upstream.cc b/src/shrpx_http2_upstream.cc index c27fada3..f19c65e4 100644 --- a/src/shrpx_http2_upstream.cc +++ b/src/shrpx_http2_upstream.cc @@ -1262,7 +1262,10 @@ int Http2Upstream::downstream_read(DownstreamConnection *dconn) { } else { auto rv = downstream->on_read(); if (rv == SHRPX_ERR_EOF) { - return downstream_eof(dconn); + if (downstream->get_request_header_sent()) { + return downstream_eof(dconn); + } + return SHRPX_ERR_RETRY; } if (rv == SHRPX_ERR_DCONN_CANCELED) { downstream->pop_downstream_connection(); diff --git a/src/shrpx_http_downstream_connection.cc b/src/shrpx_http_downstream_connection.cc index 23442bef..f68cfcf5 100644 --- a/src/shrpx_http_downstream_connection.cc +++ b/src/shrpx_http_downstream_connection.cc @@ -138,26 +138,33 @@ void connect_timeoutcb(struct ev_loop *loop, ev_timer *w, int revents) { } } // namespace +namespace { +void backend_retry(Downstream *downstream) { + retry_downstream_connection(downstream, 502); +} +} // namespace + namespace { void readcb(struct ev_loop *loop, ev_io *w, int revents) { + int rv; auto conn = static_cast(w->data); auto dconn = static_cast(conn->data); auto downstream = dconn->get_downstream(); auto upstream = downstream->get_upstream(); auto handler = upstream->get_client_handler(); - if (upstream->downstream_read(dconn) != 0) { + rv = upstream->downstream_read(dconn); + if (rv != 0) { + if (rv == SHRPX_ERR_RETRY) { + backend_retry(downstream); + return; + } + delete handler; } } } // namespace -namespace { -void backend_retry(Downstream *downstream) { - retry_downstream_connection(downstream, 502); -} -} // namespace - namespace { void writecb(struct ev_loop *loop, ev_io *w, int revents) { int rv; diff --git a/src/shrpx_https_upstream.cc b/src/shrpx_https_upstream.cc index bfe4f7c2..e4e5fbc2 100644 --- a/src/shrpx_https_upstream.cc +++ b/src/shrpx_https_upstream.cc @@ -788,7 +788,10 @@ int HttpsUpstream::downstream_read(DownstreamConnection *dconn) { rv = downstream->on_read(); if (rv == SHRPX_ERR_EOF) { - return downstream_eof(dconn); + if (downstream->get_request_header_sent()) { + return downstream_eof(dconn); + } + return SHRPX_ERR_RETRY; } if (rv == SHRPX_ERR_DCONN_CANCELED) {