Commit 544160a1 authored by ale's avatar ale

Set timeouts on outbound proxy connections

parent 89424b7d
Pipeline #6052 failed with stages
in 4 minutes and 39 seconds
......@@ -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)
......
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