From a16daf109b58a6fbacb46a9f766f03739f74df50 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Wed, 13 Apr 2016 00:36:59 +0900 Subject: [PATCH] nghttpx: Try next HTTP/1 backend address when connection cannot be made --- src/shrpx_http_downstream_connection.cc | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/shrpx_http_downstream_connection.cc b/src/shrpx_http_downstream_connection.cc index e572feb2..1d067653 100644 --- a/src/shrpx_http_downstream_connection.cc +++ b/src/shrpx_http_downstream_connection.cc @@ -102,6 +102,17 @@ void connectcb(struct ev_loop *loop, ev_io *w, int revents) { auto upstream = downstream->get_upstream(); auto handler = upstream->get_client_handler(); if (dconn->connected() != 0) { + downstream->pop_downstream_connection(); + + auto ndconn = handler->get_downstream_connection(downstream); + if (ndconn) { + if (downstream->attach_downstream_connection(std::move(ndconn)) == 0) { + return; + } + } + + downstream->set_request_state(Downstream::CONNECT_FAIL); + if (upstream->on_downstream_abort_request(downstream, 503) != 0) { delete handler; } @@ -1056,8 +1067,6 @@ int HttpDownstreamConnection::connected() { downstream_failure(addr_); - downstream_->set_request_state(Downstream::CONNECT_FAIL); - return -1; }