-
Notifications
You must be signed in to change notification settings - Fork 18.3k
Closed
Labels
Milestone
Description
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:
- There is no need to panic when cancelling a cancelled request. And no document says that is not allowed.
- 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.