net/http: HTTP/2 request context sometimes returns no error when the client disconnects #52183
Labels
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
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?
Users sometimes abort file uploads before they finish, which propagates an error up the call stack. I try to see if the HTTP request was aborted by checking
request.Context().Err() != nil
, in which case I ignore the error. Otherwise, I report it, so it can be investigated. (I am aware there might be rare cases when there is an unrelated error, after which the client disconnects, which will cause the error to be ignored, incorrectly.)I created an example.
server.go
Here is also a self-signed certificate, for convenience.
key.pem
cert.pem
I then try to start a rate-limited upload, and press Ctrl-C at random times before it completes.
HTTP/1.1:
HTTP/2:
What did you expect to see?
I expect
request.Context().Err()
to always saycontext canceled
. Is this assumption correct?What did you see instead?
In case of HTTP/1.1, it seems I always get the error
unexpected EOF
, andrequest.Context().Err()
always returnscontext canceled
.In case of HTTP/2, it seems the error is always
client disconnected
, but most of the timerequest.Context().Err()
isnil
.It seems there is some kind of race here. If I add a short sleep at the end of the handler, I get the expected context error.
I found what looks like the error that is returned, but it is unexported, so I cannot check it more directly.
The text was updated successfully, but these errors were encountered: