From 8d4ea36dec659807b6b2432930fcd27c7185f4be Mon Sep 17 00:00:00 2001 From: miyuko Date: Fri, 3 Apr 2026 00:27:58 +0000 Subject: [PATCH] Re-throw `http.ErrAbortHandler` from our panic handler. This aborts the response to the client and doesn't log an error. httputil.ReverseProxy commonly panics with this error. This results in different behavior from simply swallowing the panic. Panicking prevents flushing the response to the client, and in the case of a panic from httputil.ReverseProxy it results in clients potentially receiving an empty response instead of what was already written to http.ResponseWriter. This behavior is the same as if the panic handler hadn't been installed. --- src/main.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main.go b/src/main.go index 714a11b..7fc69aa 100644 --- a/src/main.go +++ b/src/main.go @@ -127,6 +127,9 @@ func panicHandler(handler http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { defer func() { if err := recover(); err != nil { + if err, ok := err.(error); ok && errors.Is(err, http.ErrAbortHandler) { + panic(http.ErrAbortHandler) + } logc.Printf(r.Context(), "panic: %s %s %s: %s\n%s", r.Method, r.Host, r.URL.Path, err, string(debug.Stack())) http.Error(w,