From 8aae0b64d36d611acb83c065ffaf0eb1738bdfe8 Mon Sep 17 00:00:00 2001 From: Dean Sheather Date: Mon, 20 Mar 2023 20:51:21 -0700 Subject: [PATCH] chore: avoid logging http.ErrAbortHandler panics (#6686) --- coderd/httpmw/recover.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/coderd/httpmw/recover.go b/coderd/httpmw/recover.go index a882ea7526..3d19918f8d 100644 --- a/coderd/httpmw/recover.go +++ b/coderd/httpmw/recover.go @@ -15,7 +15,13 @@ func Recover(log slog.Logger) func(h http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { defer func() { r := recover() - if r != nil { + + // Reverse proxying (among other things) may panic with + // http.ErrAbortHandler when the request is aborted. It's not a + // real panic so we shouldn't log them. + // + //nolint:errorlint // this is how the stdlib does the check + if r != nil && r != http.ErrAbortHandler { log.Warn(context.Background(), "panic serving http request (recovered)", slog.F("panic", r),