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: Transport.CancelRequest no longer cancels in-flight request #40453

neild opened this issue Jul 28, 2020 · 1 comment

net/http: Transport.CancelRequest no longer cancels in-flight request #40453

neild opened this issue Jul 28, 2020 · 1 comment


Copy link

@neild neild commented Jul 28, 2020

(*net/http.Transport).CancelRequest's documentation states:

CancelRequest should only be called after RoundTrip has returned.

Despite this warning, CancelRequest does usually cancel an in-flight request currently blocked in RoundTrip. CL 234894 has inadvertently broken this for requests with a body.

Crude reproduction case follows.

package main

import (

func init() {
        http.HandleFunc("/ok", func(w http.ResponseWriter, r *http.Request) {
                fmt.Fprintln(w, "ok")
        http.HandleFunc("/hang", func(w http.ResponseWriter, r *http.Request) {
        go http.ListenAndServe("localhost:8080", nil)

func TestHTTP(t *testing.T) {
        for {
                _, err := http.Get("http://localhost:8080/ok")
                if err == nil {

        buf := bytes.NewBuffer([]byte{1, 2, 3})

        req, err := http.NewRequest("GET", "http://localhost:8080/hang", buf)
        if err != nil {
        donec := make(chan int)
        go func() {
                defer close(donec)

        time.Sleep(100 * time.Millisecond)
@neild neild self-assigned this Jul 28, 2020
Copy link

@gopherbot gopherbot commented Jul 28, 2020

Change mentions this issue: net/http: fix cancelation of requests with a readTrackingBody wrapper

@neild neild added this to the Go1.15 milestone Jul 30, 2020
@gopherbot gopherbot closed this in f235275 Aug 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.