Skip to content

Commit 343e46f

Browse files
committed
Don't log client connection issues as Errors
ERROR panic detected: write tcp 10.1.4.25:3000->35.191.75.48:57722: i/o timeout This looks scary in the logs but seems to be just a client connection issue: Rekor has not failed here, the client connection has just been lost. Make sure the middleware recoverer does not log client connection issues as errors. Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
1 parent 3635ab2 commit 343e46f

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

pkg/generated/restapi/configure_rekor_server.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,12 @@ import (
2222
"crypto/tls"
2323
go_errors "errors"
2424
"fmt"
25+
"io"
26+
"net"
2527
"net/http"
2628
"net/http/httputil"
2729
"strconv"
30+
"syscall"
2831
"time"
2932

3033
// using embed to add the static html page duing build time
@@ -397,7 +400,22 @@ func recoverer(next http.Handler) http.Handler {
397400
fields = append(fields, zap.ByteString("request_headers", request))
398401
}
399402

400-
log.ContextLogger(ctx).With(fields...).Errorf("panic detected: %v", rvr)
403+
// Check if the panic is due to a connection issue: Don't log these
404+
// cases as serious errors
405+
isNetworkError := false
406+
if err, ok := rvr.(error); ok {
407+
if go_errors.Is(err, io.EOF) || go_errors.Is(err, syscall.EPIPE) || go_errors.Is(err, syscall.ECONNRESET) {
408+
isNetworkError = true
409+
} else if netErr, ok := err.(net.Error); ok && netErr.Timeout() {
410+
isNetworkError = true
411+
}
412+
}
413+
414+
if isNetworkError {
415+
log.ContextLogger(ctx).With(fields...).Debugf("client connection closed: %v", rvr)
416+
} else {
417+
log.ContextLogger(ctx).With(fields...).Errorf("panic detected: %v", rvr)
418+
}
401419

402420
errors.ServeError(w, r, nil)
403421
}

0 commit comments

Comments
 (0)