diff --git a/node/proxy.go b/node/proxy.go index 2baa027549c7263f6595992f16811bbb130576d1..97e0ebe58f628e79d97b4d7059058d9256a1f4da 100644 --- a/node/proxy.go +++ b/node/proxy.go @@ -23,6 +23,13 @@ import ( "github.com/prometheus/client_golang/prometheus" ) +var ( + dialer = &net.Dialer{ + Timeout: 10 * time.Second, + } + requestWriteTimeout = 10 * time.Second +) + func copyHeader(dst, src http.Header) { for k, vv := range src { for _, v := range vv { @@ -97,7 +104,7 @@ func doIcecastProxy(rw http.ResponseWriter, req *http.Request, target *url.URL, // Create the upstream connection and write the HTTP request // to it. - upstream, err := net.Dial("tcp", outreq.URL.Host) + upstream, err := dialer.Dial("tcp", outreq.URL.Host) if err != nil { log.Printf("http: proxy dial error: %v", err) rw.WriteHeader(http.StatusInternalServerError) @@ -105,6 +112,8 @@ func doIcecastProxy(rw http.ResponseWriter, req *http.Request, target *url.URL, return } defer upstream.Close() + 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)