-
Notifications
You must be signed in to change notification settings - Fork 18k
net/http: HTTP/2 request context sometimes returns no error when the client disconnects #52183
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
Comments
cc @neild |
I've created a test that reproduces this. The client is now in Go, so there is no need to run I just make a POST request and abort it before sending any data. On the server side, the request context is cancelled when using HTTP/1.1, but not when using HTTP/2. I couldn't think of a better way to abort the client request, but this does reproduce the issue. There are two main differences in the HTTPS version relative to the HTTP one:
A minor difference is that, in the HTTPS version, the error reported by I tried it with Go versions 1.17.12 and 1.19.3. It would be useful to know if the request context not being cancelled immediately is normal and maybe I just have incorrect expectations.
|
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: