-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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
net/http: Program crash when handling panic with wrapped http.ErrAbortHandler
#62510
Comments
http.ErrAbortHandler
Change https://go.dev/cl/526418 mentions this issue: |
http.ErrAbortHandler
http.ErrAbortHandler
cc @neild |
Change https://go.dev/cl/526171 mentions this issue: |
The
https://go.dev/cl/526171 proposes changing I'm uncertain about the special handling of |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
The
net/http.conn.serve
method is equipped to handle a special case for when panic is called withhttp.ErrAbortHandler
by downstreamhttp.Handler
implementations where it silently recovers and prevents the program from crashing.When chaining
http.Handler
implementations, if anhttp.Handler
usesgolang.org/x/sync/singleflight.Group
, and anhttp.Handler
downstream of that panics withhttp.ErrAbortHandler
, thesingleflight
package recovers from the panic first, wraps the panic value in its own private error type, and re-panics with its private type. When the new panic gets tonet/http.conn.serve
, a direct comparison is made to see iferr != ErrAbortHandler
. Since technicallyerr
is notErrAbortHandler
, just another error type that wrapsErrAbortHandler
,net/http.conn.serve
does not handle the special case and allows the program to crash.Example where
net/http.conn.serve
handles the panic and the program does not crash:Example using
golang.org/x/sync/singleflight.Group
wherenet/http.conn.serve
does not handle the panic and the program crashes:What did you expect to see?
When using
golang.org/x/sync/singleflight.Group
in a chain ofhttp.Handler
implementations where apanic(http.ErrAbortHandler
is called downstream,net/http.conn.serve
is able to unwrap errors to determine if the error is actuallyhttp.ErrAbortHandler
and handle the panic without allowing the program to crash.What did you see instead?
The program crashes with the message
panic: net/http: abort Handler
.The text was updated successfully, but these errors were encountered: