New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
middleware: recoverer ignores http.ErrAbortHandler #588
Comments
I'm a bit confused.. how should we handle the current middleware: https://github.com/go-chi/chi/blob/master/middleware/recoverer.go#L22 looks like so: func Recoverer(next http.Handler) http.Handler {
fn := func(w http.ResponseWriter, r *http.Request) {
defer func() {
if rvr := recover(); rvr != nil && rvr != http.ErrAbortHandler {
logEntry := GetLogEntry(r)
if logEntry != nil {
logEntry.Panic(rvr, debug.Stack())
} else {
PrintPrettyStack(rvr)
}
w.WriteHeader(http.StatusInternalServerError)
}
}()
next.ServeHTTP(w, r)
}
return http.HandlerFunc(fn)
} suggestion is to change it to....? func Recoverer(next http.Handler) http.Handler {
fn := func(w http.ResponseWriter, r *http.Request) {
defer func() {
if rvr := recover(); rvr != nil {
logEntry := GetLogEntry(r)
if logEntry != nil {
logEntry.Panic(rvr, debug.Stack())
} else {
PrintPrettyStack(rvr)
}
if rvr == http.ErrAbortHandler {
panic(rvr)
}
w.WriteHeader(http.StatusInternalServerError)
}
}()
next.ServeHTTP(w, r)
}
return http.HandlerFunc(fn)
} so, we log and re-raise the panic..? or something else is suggested here..? |
please take a look at #624, the panic should not be logged https://go.googlesource.com/go/+/master/src/net/http/server.go#1793 |
I get it now, thank you. Do you mind rebasing your PR and I will then merge it? |
This error is generally used to abort a request while streaming a response so it should not be recovered otherwise the request is not aborted and the client does not detect the error Fixes go-chi#588
Dome, thank you |
The http.ErrAbortHandler panic usually causes a connection close. The recoverer just ignores the panic instead of reraising it causing connection leaks.
The text was updated successfully, but these errors were encountered: