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.RoundTrip regression when retrying requests on Request.Body read error #18239

bradfitz opened this issue Dec 8, 2016 · 4 comments


Copy link

@bradfitz bradfitz commented Dec 8, 2016

Bug report from Docker: from moby/moby#29030

Repro from the change where I'm working on a fix:

func TestTransportBodyReadError(t *testing.T) {  
        defer afterTest(t)  
        ts := httptest.NewServer(HandlerFunc(func(w ResponseWriter, r *Request) {  
                if r.URL.Path == "/ping" {  
                buf := make([]byte, 1)  
                n, err := r.Body.Read(buf)  
                w.Header().Set("X-Body-Read", fmt.Sprintf("%v, %v", n, err))  
        defer ts.Close()  
        tr := &Transport{}  
        defer tr.CloseIdleConnections()  
        c := &Client{Transport: tr}  
        res, err := c.Get(ts.URL + "/ping")  
        if err != nil {  
        r, w := io.Pipe()  
        errClose := errors.New("some error")  
        if _, err := c.Post(ts.URL+"/test", "", r); err != nil {  
                t.Logf("Got error: %v", err)  

Go 1.7 always says "some error" as the error. In Go 1.8, we read from the request body, get an error, and then try to send the request again since we never wrote anything. But the first write ends up closing the request body (the pipe), and it can't be read the second time.

We need to do the same thing @tombergan and I did for http2 in golang/net@8dab929 and not retry a request once its Body has been messed with, unless it has a GetBody func that can be used to reset itself.

/cc @cpuguy83

@bradfitz bradfitz added the NeedsFix label Dec 8, 2016
@bradfitz bradfitz added this to the Go1.8 milestone Dec 8, 2016
@bradfitz bradfitz self-assigned this Dec 8, 2016
Copy link

@cpuguy83 cpuguy83 commented Dec 8, 2016

Thanks for opening, was going to do this once the kids went to bed!

Copy link

@gopherbot gopherbot commented Dec 8, 2016

CL mentions this issue.

Copy link

@cpuguy83 cpuguy83 commented Dec 8, 2016

Confirmed the changes in the CL fix our issue.

@gopherbot gopherbot closed this in 9296d4e Dec 8, 2016
Copy link

@cpuguy83 cpuguy83 commented Dec 8, 2016


@golang golang locked and limited conversation to collaborators Dec 8, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

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