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: CancelRequest twice on the same request panics #10405

yichengq opened this issue Apr 10, 2015 · 1 comment


None yet
3 participants
Copy link

commented Apr 10, 2015

If i call CancelRequest twice on the same request, CancelRequest will panic because of close a closed channel at here:

I argue that CancelRequest should not panic here:

  1. There is no need to panic when cancelling a cancelled request. And no document says that is not allowed.
  2. It is hard to ensure a request is canceled without CancelRequest retry:
    go func() { c <- f(client.Do(req)) }()
    select {
    case <-ctx.Done():
        <-c // Wait for f to return.
        return ctx.Err()
    case err := <-c:
        return err

(code from
It is possible that the request is canceled before Do is called, and it needs CancelRequest retry to ensure it is canceled.


@bradfitz bradfitz self-assigned this Apr 10, 2015

@bradfitz bradfitz added this to the Go1.5 milestone Apr 10, 2015


This comment has been minimized.

Copy link

commented Apr 20, 2015

@bradfitz bradfitz closed this in b016eba Apr 20, 2015

@golang golang locked and limited conversation to collaborators Jun 25, 2016

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.