net/http: canceled requests with Timeout set always return a Timeout error #16094

Closed
FiloSottile opened this Issue Jun 17, 2016 · 10 comments

Comments

Projects
None yet
8 participants
Member

FiloSottile commented Jun 17, 2016

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 from Canceled requests with timeout always mention Client.Timeout in the error to 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

Member

FiloSottile commented Jun 17, 2016

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

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

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

Owner

bradfitz commented Jun 29, 2016

@FiloSottile, is this a regression from Go 1.6?

Member

FiloSottile commented Jun 29, 2016

@quentinmit quentinmit added the NeedsFix label Oct 7, 2016

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

@bradfitz bradfitz self-assigned this Nov 10, 2016

@gopherbot gopherbot closed this in 7448eb4 Nov 10, 2016

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

Owner

bradfitz commented Jan 26, 2017

@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 commented Mar 6, 2017

Where is cancelTimerBody.Read used?

Owner

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 join this conversation on GitHub. Already have an account? Sign in to comment