Skip to content

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

Closed

Description

@FiloSottile

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).

Activity

  1. 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[/+] on Jun 17, 2016
  2. added this to the Go1.8 milestone on Jun 17, 2016
  3. FiloSottile commented on Jun 17, 2016

    @FiloSottile
    ContributorAuthor

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

  4. 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[/+] on Jun 17, 2016
  5. gopherbot commented on Jun 17, 2016

    @gopherbot
    Contributor

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

  6. bradfitz commented on Jun 29, 2016

    @bradfitz
    Contributor

    @FiloSottile, is this a regression from Go 1.6?

  7. FiloSottile commented on Jun 29, 2016

    @FiloSottile
    ContributorAuthor
  8. added
    NeedsFixThe path to resolution is known, but the work has not been done.
    on Oct 7, 2016
  9. odeke-em commented on Nov 1, 2016

    @odeke-em
    Member
  10. gopherbot commented on Nov 1, 2016

    @gopherbot
    Contributor

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

  11. self-assigned this
    on Nov 10, 2016
  12. KingRider commented on Jan 26, 2017

    @KingRider

    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

  13. bradfitz commented on Jan 26, 2017

    @bradfitz
    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.

  14. keitaj commented on Mar 6, 2017

    @keitaj

    Where is cancelTimerBody.Read used?

  15. bradfitz commented on Mar 6, 2017

    @bradfitz
    Contributor

    @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.

  16. locked and limited conversation to collaborators on Mar 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions