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

Closed
bradfitz opened this issue Dec 8, 2016 · 4 comments
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@bradfitz
Copy link
Contributor

bradfitz commented Dec 8, 2016

Bug report from Docker:

https://twitter.com/cpuguy83/status/806263794368397312 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" {  
                        return  
                }  
                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 {  
                t.Fatal(err)  
        }  
        res.Body.Close()  
  
        r, w := io.Pipe()  
        errClose := errors.New("some error")  
        w.CloseWithError(errClose)  
        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 The path to resolution is known, but the work has not been done. label Dec 8, 2016
@bradfitz bradfitz added this to the Go1.8 milestone Dec 8, 2016
@bradfitz bradfitz self-assigned this Dec 8, 2016
@cpuguy83
Copy link

cpuguy83 commented Dec 8, 2016

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

@gopherbot
Copy link

CL https://golang.org/cl/34134 mentions this issue.

@cpuguy83
Copy link

cpuguy83 commented Dec 8, 2016

Confirmed the changes in the CL fix our issue.

@cpuguy83
Copy link

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.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

3 participants