From 2c7b7cd6ca1bd0a54abb6950703c524de24c524f Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 12 Oct 2018 13:04:02 +0200 Subject: [PATCH] Fix recover from panic handler --- middlewares/recover.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/middlewares/recover.go b/middlewares/recover.go index 79af9eee4..bde96326d 100644 --- a/middlewares/recover.go +++ b/middlewares/recover.go @@ -27,7 +27,16 @@ func NegroniRecoverHandler() negroni.Handler { func recoverFunc(w http.ResponseWriter) { if err := recover(); err != nil { - log.Errorf("Recovered from panic in http handler: %+v", err) - http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError) + if shouldLogPanic(err) { + log.Errorf("Recovered from panic in http handler: %+v", err) + http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError) + } else { + log.Debugf("HTTP handler has been aborted: %v", err) + } } } + +// https://github.com/golang/go/blob/c33153f7b416c03983324b3e8f869ce1116d84bc/src/net/http/httputil/reverseproxy.go#L284 +func shouldLogPanic(panicValue interface{}) bool { + return panicValue != nil && panicValue != http.ErrAbortHandler +}