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: make Transport use GetBody, retry requests when no bytes were written #18241

bradfitz opened this issue Dec 8, 2016 · 5 comments


Copy link

@bradfitz bradfitz commented Dec 8, 2016

#15723 ( for Go 1.8 was too aggressive and buggy.

It was partially rolled back (see #18239).

This bug tracks fixing it properly for Go 1.9.

/cc @tombergan

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

@gopherbot gopherbot commented Dec 8, 2016

CL mentions this issue.

gopherbot pushed a commit that referenced this issue Dec 8, 2016
This rolls back partly, softening it so it
only retries POST/PUT/DELETE etc requests where there's no Body (nil
or NoBody). This is a little useless, since most idempotent requests
have a body (except maybe DELETE), but it's late in the Go 1.8 release
cycle and I want to do the proper fix.

The proper fix will look like what we did for http2 and only retrying
the request if Request.GetBody is defined, and then creating a new request
for the next attempt. See for the http2 fix.

Updates #15723
Fixes #18239
Updates #18241

Change-Id: I6ebaa1fd9b19b5ccb23c8d9e7b3b236e71cf57f3
Run-TryBot: Brad Fitzpatrick <>
TryBot-Result: Gobot Gobot <>
Reviewed-by: Tom Bergan <>
Copy link

@rogpeppe rogpeppe commented Dec 12, 2016

I'm not convinced about GetBody as an abstraction - it's not natural when using some kinds of obviously-retriable bodies such as files. Why not just seek to the body start if it implements io.Seeker? (you'd probably want to make that behaviour opt-in rather than opt-out).

Copy link
Contributor Author

@bradfitz bradfitz commented Dec 12, 2016

But since you need an opt-in anyway, this seems like a reasonable opt-in. And we can't change our previous Close behavior, so seeking back to the beginning of a closed file obviously isn't going to work. Plus the more experience I have with type sniffing magic, the more it bites me. I like the explicitness of GetBody. GetBody is not just for Transport retries on network failures, but also Client redirects, replaying the request body. Trying to reuse the same Body while coordinating across those two layers (not forgetting http2) and without adding new API surface seems like it'd be gross.

I'm not sure this is the best place to discuss GetBody, though.

Copy link

@odeke-em odeke-em commented Apr 25, 2017

@bradfitz should we fold this issue into #17844? I ask since this one is more recent and no bytes written might be considered idempotency, so this one becomes a subset of the mentioned issue.

Copy link

@gopherbot gopherbot commented Apr 28, 2017

CL mentions this issue.

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
4 participants