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

Slight improvement in error logging

parent 2f7945b3
Branches
Tags
No related merge requests found
...@@ -141,7 +141,7 @@ func withMount(n *Node, f func(*pb.Mount, http.ResponseWriter, *http.Request)) h ...@@ -141,7 +141,7 @@ func withMount(n *Node, f func(*pb.Mount, http.ResponseWriter, *http.Request)) h
mountPath := strings.TrimSuffix(r.URL.Path, ".m3u") mountPath := strings.TrimSuffix(r.URL.Path, ".m3u")
mount, ok := n.mounts.GetMount(mountPath) mount, ok := n.mounts.GetMount(mountPath)
if !ok { if !ok {
log.Printf("http: %s: not found", mountPath) //log.Printf("http: %s: mount point not found", mountPath)
http.NotFound(w, r) http.NotFound(w, r)
return return
} }
...@@ -152,7 +152,7 @@ func withMount(n *Node, f func(*pb.Mount, http.ResponseWriter, *http.Request)) h ...@@ -152,7 +152,7 @@ func withMount(n *Node, f func(*pb.Mount, http.ResponseWriter, *http.Request)) h
func serveSource(n *Node, mount *pb.Mount, w http.ResponseWriter, r *http.Request) { func serveSource(n *Node, mount *pb.Mount, w http.ResponseWriter, r *http.Request) {
// Can't connect sources to relay streams. // Can't connect sources to relay streams.
if mount.IsRelay() { if mount.IsRelay() {
log.Printf("source connection to relay stream %s", mount.Path) log.Printf("error: source connection to relay stream %s", mount.Path)
http.Error(w, "Stream is relayed, no source connections allowed", http.StatusBadRequest) http.Error(w, "Stream is relayed, no source connections allowed", http.StatusBadRequest)
return return
} }
...@@ -184,7 +184,7 @@ func serveRedirect(lb *loadBalancer, mount *pb.Mount, w http.ResponseWriter, r * ...@@ -184,7 +184,7 @@ func serveRedirect(lb *loadBalancer, mount *pb.Mount, w http.ResponseWriter, r *
// 1:1 mapping between Icecasts and frontends. // 1:1 mapping between Icecasts and frontends.
targetNode := lb.chooseNode(&httpRequestContext{r}) targetNode := lb.chooseNode(&httpRequestContext{r})
if targetNode == nil { if targetNode == nil {
log.Printf("http: %s: no nodes available", mount.Path) log.Printf("error: http: %s: no nodes available", mount.Path)
http.Error(w, "No nodes available", http.StatusServiceUnavailable) http.Error(w, "No nodes available", http.StatusServiceUnavailable)
return return
} }
......
...@@ -64,7 +64,7 @@ type wrappedWriter interface { ...@@ -64,7 +64,7 @@ type wrappedWriter interface {
// request. The additional streamName parameter is used for // request. The additional streamName parameter is used for
// instrumentation. // instrumentation.
func doIcecastProxy(rw http.ResponseWriter, req *http.Request, target *url.URL, streamName string) { func doIcecastProxy(rw http.ResponseWriter, req *http.Request, target *url.URL, streamName string) {
log.Printf("proxy: in=%s out=%s stream=%s", req.URL.String(), target.String(), streamName) //log.Printf("proxy: in=%s out=%s stream=%s", req.URL.String(), target.String(), streamName)
outreq := new(http.Request) outreq := new(http.Request)
*outreq = *req // includes shallow copies of maps, but okay *outreq = *req // includes shallow copies of maps, but okay
...@@ -119,7 +119,7 @@ func doIcecastProxy(rw http.ResponseWriter, req *http.Request, target *url.URL, ...@@ -119,7 +119,7 @@ func doIcecastProxy(rw http.ResponseWriter, req *http.Request, target *url.URL,
// to it. // to it.
upstream, err := dialer.Dial("tcp", outreq.URL.Host) upstream, err := dialer.Dial("tcp", outreq.URL.Host)
if err != nil { if err != nil {
log.Printf("http: proxy dial error: %v", err) log.Printf("error: http: proxy dial error: %v", err)
rw.WriteHeader(http.StatusInternalServerError) rw.WriteHeader(http.StatusInternalServerError)
proxyConnectErrs.WithLabelValues(streamName, target.Host).Inc() proxyConnectErrs.WithLabelValues(streamName, target.Host).Inc()
return return
...@@ -130,7 +130,7 @@ func doIcecastProxy(rw http.ResponseWriter, req *http.Request, target *url.URL, ...@@ -130,7 +130,7 @@ func doIcecastProxy(rw http.ResponseWriter, req *http.Request, target *url.URL,
// stuck on unresponsive TCP servers. // stuck on unresponsive TCP servers.
upstream.SetDeadline(time.Now().Add(requestWriteTimeout)) // nolint: errcheck upstream.SetDeadline(time.Now().Add(requestWriteTimeout)) // nolint: errcheck
if err := outreq.Write(upstream); err != nil { if err := outreq.Write(upstream); err != nil {
log.Printf("http: proxy request write error: %v", err) log.Printf("error: http: proxy request write error: %v", err)
rw.WriteHeader(http.StatusInternalServerError) rw.WriteHeader(http.StatusInternalServerError)
proxyConnectErrs.WithLabelValues(streamName, target.Host).Inc() proxyConnectErrs.WithLabelValues(streamName, target.Host).Inc()
return return
...@@ -147,7 +147,7 @@ func doIcecastProxy(rw http.ResponseWriter, req *http.Request, target *url.URL, ...@@ -147,7 +147,7 @@ func doIcecastProxy(rw http.ResponseWriter, req *http.Request, target *url.URL,
var err error var err error
conn, _, err = h.Hijack() conn, _, err = h.Hijack()
if err != nil { if err != nil {
log.Printf("http: proxy hijack error: %v", err) log.Printf("error: http: proxy hijack error: %v", err)
rw.WriteHeader(http.StatusInternalServerError) rw.WriteHeader(http.StatusInternalServerError)
return return
} }
...@@ -159,13 +159,13 @@ func doIcecastProxy(rw http.ResponseWriter, req *http.Request, target *url.URL, ...@@ -159,13 +159,13 @@ func doIcecastProxy(rw http.ResponseWriter, req *http.Request, target *url.URL,
} }
} }
if conn == nil { if conn == nil {
log.Printf("http: proxy error: could not find hijackable connection") log.Printf("error: http: proxy error: could not find hijackable connection")
http.Error(rw, "could not find hijackable connection", http.StatusInternalServerError) http.Error(rw, "could not find hijackable connection", http.StatusInternalServerError)
return return
} }
defer conn.Close() defer conn.Close()
if err := conn.SetDeadline(time.Time{}); err != nil { if err := conn.SetDeadline(time.Time{}); err != nil {
log.Printf("http: proxy setdeadline error: %v", err) log.Printf("error: http: proxy setdeadline error: %v", err)
} }
// Run two-way proxying. // Run two-way proxying.
...@@ -190,16 +190,17 @@ func copyStream(tag string, out io.WriteCloser, in io.ReadCloser, promCounter pr ...@@ -190,16 +190,17 @@ func copyStream(tag string, out io.WriteCloser, in io.ReadCloser, promCounter pr
if cntr != nil { if cntr != nil {
atomic.AddUint64(cntr, uint64(n)) atomic.AddUint64(cntr, uint64(n))
} }
if err != nil && !isCloseError(err) { if err != nil && isInterestingError(err) {
log.Printf("http: proxy error (%s): %v", tag, err) log.Printf("error: http: proxy error (%s): %v", tag, err)
} }
} }
// This is a bad implementation (see https://github.com/golang/go/issues/4373 // This is a bad implementation (see https://github.com/golang/go/issues/4373
// for some notes on why it is a layering violation), and we could replace it // for some notes on why it is a layering violation), and we could replace it
// with an atomic 'closing' flag. // with an atomic 'closing' flag.
func isCloseError(err error) bool { func isInterestingError(err error) bool {
return strings.Contains(err.Error(), "use of closed network connection") s := err.Error()
return !(strings.Contains(s, "use of closed network connection") || strings.Contains(s, "connection reset by peer"))
} }
// Simple two-way TCP proxy that copies data in both directions and // Simple two-way TCP proxy that copies data in both directions and
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment