net/http: Program crash when handling panic with wrapped http.ErrAbortHandler
#62510
Labels
NeedsDecision
Feedback is required from experts, contributors, and/or the community before a change can be made.
Milestone
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: