Skip to content
Snippets Groups Projects
Commit 544160a1 authored by ale's avatar ale
Browse files

Set timeouts on outbound proxy connections

parent 89424b7d
Branches
No related tags found
No related merge requests found
......@@ -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)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment