Commit b9f41e34 authored by Tatsuhiro Tsujikawa's avatar Tatsuhiro Tsujikawa

nghttpx: Return error when downstream HTTP/1 connection attempt failed

parent ca7288ae
......@@ -69,6 +69,25 @@ func TestH1H1MultipleRequestCL(t *testing.T) {
}
}
func TestH1H1ConnectFailure(t *testing.T) {
st := newServerTester(nil, t, noopHandler)
defer st.Close()
// shutdown backend server to simulate backend connect failure
st.ts.Close()
res, err := st.http1(requestParam{
name: "TestH1H1ConnectFailure",
})
if err != nil {
t.Fatalf("Error st.http2() = %v", err)
}
want := 502
if got := res.status; got != want {
t.Errorf("status: %v; want %v", got, want)
}
}
func TestH2H1PlainGET(t *testing.T) {
st := newServerTester(nil, t, noopHandler)
defer st.Close()
......@@ -305,6 +324,25 @@ func TestH2H1InvalidRequestCL(t *testing.T) {
}
}
func TestH2H1ConnectFailure(t *testing.T) {
st := newServerTester(nil, t, noopHandler)
defer st.Close()
// shutdown backend server to simulate backend connect failure
st.ts.Close()
res, err := st.http2(requestParam{
name: "TestH2H1ConnectFailure",
})
if err != nil {
t.Fatalf("Error st.http2() = %v", err)
}
want := 502
if got := res.status; got != want {
t.Errorf("status: %v; want %v", got, want)
}
}
func TestH2H2MultipleResponseCL(t *testing.T) {
st := newServerTester([]string{"--http2-bridge"}, t, func(w http.ResponseWriter, r *http.Request) {
w.Header().Add("content-length", "1")
......
......@@ -95,7 +95,9 @@ void connectcb(struct ev_loop *loop, ev_io *w, int revents) {
auto upstream = downstream->get_upstream();
auto handler = upstream->get_client_handler();
if (dconn->on_connect() != 0) {
delete handler;
if (upstream->downstream_error(dconn, Downstream::EVENT_ERROR) != 0) {
delete handler;
}
return;
}
writecb(loop, w, revents);
......@@ -747,6 +749,9 @@ end:
int HttpDownstreamConnection::on_connect() {
if (!util::check_socket_connected(fd_)) {
if (LOG_ENABLED(INFO)) {
DLOG(INFO, this) << "downstream connect failed";
}
return -1;
}
......
......@@ -560,6 +560,8 @@ int HttpsUpstream::downstream_error(DownstreamConnection *dconn, int events) {
return -1;
}
handler_->set_should_close_after_write(true);
unsigned int status;
if (events & Downstream::EVENT_TIMEOUT) {
status = 504;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment