From a67b44ea60cbad9296260df7dee09e9da2551bd9 Mon Sep 17 00:00:00 2001 From: ale <ale@incal.net> Date: Thu, 28 Jan 2021 15:25:06 +0000 Subject: [PATCH] Slight improvement in error logging --- node/http.go | 6 +++--- node/proxy.go | 21 +++++++++++---------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/node/http.go b/node/http.go index 1e75ae62..ac468ddd 100644 --- a/node/http.go +++ b/node/http.go @@ -141,7 +141,7 @@ func withMount(n *Node, f func(*pb.Mount, http.ResponseWriter, *http.Request)) h mountPath := strings.TrimSuffix(r.URL.Path, ".m3u") mount, ok := n.mounts.GetMount(mountPath) if !ok { - log.Printf("http: %s: not found", mountPath) + //log.Printf("http: %s: mount point not found", mountPath) http.NotFound(w, r) return } @@ -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) { // Can't connect sources to relay streams. 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) return } @@ -184,7 +184,7 @@ func serveRedirect(lb *loadBalancer, mount *pb.Mount, w http.ResponseWriter, r * // 1:1 mapping between Icecasts and frontends. targetNode := lb.chooseNode(&httpRequestContext{r}) 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) return } diff --git a/node/proxy.go b/node/proxy.go index 9b94d829..c642eb9b 100644 --- a/node/proxy.go +++ b/node/proxy.go @@ -64,7 +64,7 @@ type wrappedWriter interface { // request. The additional streamName parameter is used for // instrumentation. 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 = *req // includes shallow copies of maps, but okay @@ -119,7 +119,7 @@ func doIcecastProxy(rw http.ResponseWriter, req *http.Request, target *url.URL, // to it. upstream, err := dialer.Dial("tcp", outreq.URL.Host) if err != nil { - log.Printf("http: proxy dial error: %v", err) + log.Printf("error: http: proxy dial error: %v", err) rw.WriteHeader(http.StatusInternalServerError) proxyConnectErrs.WithLabelValues(streamName, target.Host).Inc() return @@ -130,7 +130,7 @@ func doIcecastProxy(rw http.ResponseWriter, req *http.Request, target *url.URL, // 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) + log.Printf("error: http: proxy request write error: %v", err) rw.WriteHeader(http.StatusInternalServerError) proxyConnectErrs.WithLabelValues(streamName, target.Host).Inc() return @@ -147,7 +147,7 @@ func doIcecastProxy(rw http.ResponseWriter, req *http.Request, target *url.URL, var err error conn, _, err = h.Hijack() if err != nil { - log.Printf("http: proxy hijack error: %v", err) + log.Printf("error: http: proxy hijack error: %v", err) rw.WriteHeader(http.StatusInternalServerError) return } @@ -159,13 +159,13 @@ func doIcecastProxy(rw http.ResponseWriter, req *http.Request, target *url.URL, } } 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) return } defer conn.Close() 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. @@ -190,16 +190,17 @@ func copyStream(tag string, out io.WriteCloser, in io.ReadCloser, promCounter pr if cntr != nil { atomic.AddUint64(cntr, uint64(n)) } - if err != nil && !isCloseError(err) { - log.Printf("http: proxy error (%s): %v", tag, err) + if err != nil && isInterestingError(err) { + log.Printf("error: http: proxy error (%s): %v", tag, err) } } // 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 // with an atomic 'closing' flag. -func isCloseError(err error) bool { - return strings.Contains(err.Error(), "use of closed network connection") +func isInterestingError(err error) bool { + 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 -- GitLab