Skip to content
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: canceled requests with Timeout set always return a Timeout error #16094

Closed
FiloSottile opened this issue Jun 17, 2016 · 10 comments
Closed
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@FiloSottile
Copy link
Contributor

Please answer these questions before submitting your issue. Thanks!

  1. What version of Go are you using (go version)?

go version devel +9e8fa1e Fri Jun 17 15:18:39 2016 +0000 darwin/amd64

  1. What did you do?

Make a http.Client with a Timeout. Cancel the request.

https://play.golang.org/p/v-QbAxdj-3

  1. What did you expect to see?

If the cause was not a Client.Timeout, then the error should be left alone.

net/http: request canceled
  1. What did you see instead?

The error is

net/http: request canceled (Client.Timeout exceeded while reading body)

This is because reqWasCanceled returns true whatever the reason for the cancelation is, be it a library user cancel or a Timeout. Then cancelTimerBody.Read uses that function to add the message.

The (Client.Timeout exceeded while awaiting headers) message is more likely to be correct (even if slightly racy), because it only adds the message if !deadline.IsZero() && !time.Now().Before(deadline).

@ianlancetaylor ianlancetaylor changed the title Canceled requests with timeout always mention Client.Timeout in the error net/http: canceled requests with timeout always mention Client.Timeout in the error Jun 17, 2016
@ianlancetaylor ianlancetaylor added this to the Go1.8 milestone Jun 17, 2016
@FiloSottile
Copy link
Contributor Author

Looking into it, this is not only the error message. The error is actually a net Timeout.

@FiloSottile FiloSottile changed the title net/http: canceled requests with timeout always mention Client.Timeout in the error net/http: canceled requests with Timeout set always return a Timeout error Jun 17, 2016
@gopherbot
Copy link

CL https://golang.org/cl/24230 mentions this issue.

@bradfitz
Copy link
Contributor

@FiloSottile, is this a regression from Go 1.6?

@FiloSottile
Copy link
Contributor Author

FiloSottile commented Jun 29, 2016 via email

@odeke-em
Copy link
Member

odeke-em commented Nov 1, 2016

@gopherbot
Copy link

CL https://golang.org/cl/32478 mentions this issue.

@bradfitz bradfitz self-assigned this Nov 10, 2016
@KingRider
Copy link

KingRider commented Jan 26, 2017

return stopTimer, timedOut.isSet
is wrong!

Check L303
https://go-review.googlesource.com/#/c/32478/1/src/net/http/client.go@303

Please is what correct? But a continue problem

net/http: TLS handshake timeout

@bradfitz
Copy link
Contributor

@KingRider, we don't track comments on closed issues. Please file a new bug if you have a reproducible problem with the Go master branch.

@keitaj
Copy link

keitaj commented Mar 6, 2017

Where is cancelTimerBody.Read used?

@bradfitz
Copy link
Contributor

bradfitz commented Mar 6, 2017

@keitaj, we don't track comments on closed issues. Please file a new bug if you have a reproducible problem with the Go master branch.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

8 participants