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

Closed
yichengq opened this issue Apr 10, 2015 · 1 comment
Closed

net/http: CancelRequest twice on the same request panics #10405

yichengq opened this issue Apr 10, 2015 · 1 comment
Milestone

Comments

@yichengq
Copy link

If i call CancelRequest twice on the same request, CancelRequest will panic because of close a closed channel at here:
https://golang.org/src/net/http/transport.go#L517

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():
        tr.CancelRequest(req)
        <-c // Wait for f to return.
        return ctx.Err()
    case err := <-c:
        return err
    }

(code from https://blog.golang.org/context)
It is possible that the request is canceled before Do is called, and it needs CancelRequest retry to ensure it is canceled.

from https://github.com/coreos/go-etcd/issues/197

@bradfitz bradfitz self-assigned this Apr 10, 2015
@bradfitz bradfitz added this to the Go1.5 milestone Apr 10, 2015
@bradfitz
Copy link
Contributor

@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.
Projects
None yet
Development

No branches or pull requests

3 participants