From a04083e1f86dc590d89b6fbb9fd009501d4e8ad1 Mon Sep 17 00:00:00 2001 From: ale <ale@incal.net> Date: Sun, 1 Mar 2020 11:21:51 +0000 Subject: [PATCH] Reset the timeout on upstream connection after writing the request --- node/bindata.go | 4 ++-- node/proxy.go | 5 ++++- node/proxy_test.go | 4 ++-- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/node/bindata.go b/node/bindata.go index f83a365b..6339d52f 100644 --- a/node/bindata.go +++ b/node/bindata.go @@ -552,7 +552,7 @@ var _templatesIndexHtml = []byte(`<!DOCTYPE html> <div class="row"> <p> <small> - Click on a stream to listen to it.<br> + Click on a stream to listen to it. Hover on a stream to see more details. </small> </p> @@ -583,7 +583,7 @@ func templatesIndexHtml() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "templates/index.html", size: 2968, mode: os.FileMode(420), modTime: time.Unix(1581689120, 0)} + info := bindataFileInfo{name: "templates/index.html", size: 2964, mode: os.FileMode(420), modTime: time.Unix(1582995315, 0)} a := &asset{bytes: bytes, info: info} return a, nil } diff --git a/node/proxy.go b/node/proxy.go index 97e0ebe5..b9176e54 100644 --- a/node/proxy.go +++ b/node/proxy.go @@ -112,14 +112,17 @@ func doIcecastProxy(rw http.ResponseWriter, req *http.Request, target *url.URL, return } defer upstream.Close() - upstream.SetDeadline(time.Now().Add(requestWriteTimeout)) // nolint: errcheck + // Send the request upstream, with a timeout so we don't get + // stuck on unresponsive TCP servers. + upstream.SetDeadline(time.Now().Add(requestWriteTimeout)) // nolint: errcheck if err := outreq.Write(upstream); err != nil { log.Printf("http: proxy request write error: %v", err) rw.WriteHeader(http.StatusInternalServerError) proxyConnectErrs.WithLabelValues(streamName, target.Host).Inc() return } + upstream.SetDeadline(time.Time{}) // nolint: errcheck // Hijack the request connection. We might need to unroll the // layers of nested WrappedWriters, until we find a diff --git a/node/proxy_test.go b/node/proxy_test.go index 9f09f6f2..e0a31915 100644 --- a/node/proxy_test.go +++ b/node/proxy_test.go @@ -114,8 +114,8 @@ func TestProxy(t *testing.T) { }() } - // Now wait 10 seconds. - time.Sleep(10 * time.Second) + // Now wait 30 seconds, longer than request timeouts. + time.Sleep(30 * time.Second) stopProxyTest() for i := 0; i < streams; i++ { -- GitLab