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: Request Body error should not be ignored #7521

Closed
bancek opened this issue Mar 12, 2014 · 6 comments
Closed

net/http: Request Body error should not be ignored #7521

bancek opened this issue Mar 12, 2014 · 6 comments
Milestone

Comments

@bancek
Copy link

bancek commented Mar 12, 2014

What does 'go version' print?
go version go1.2.1 linux/amd64

What steps reproduce the problem?
If possible, include a link to a program on play.golang.org.

1. Do a HTTP POST request for body with error and no content

http://play.golang.org/p/bJzoJS1ZXQ

What happened?
Body error is ignored if body has no content (error happends on first Read call)

What should have happened instead?
Request should be aborted.

Please provide any additional information below.
Error is ignored when reading first byte.
https://code.google.com/p/go/source/browse/src/pkg/net/http/transfer.go#56
@bradfitz
Copy link
Contributor

Comment 1:

Labels changed: added release-go1.3, repo-main.

Owner changed to @bradfitz.

Status changed to Accepted.

@bradfitz
Copy link
Contributor

Comment 2:

Looks like Request.Write & transfer.go's WriteBody are fine, and properly return the
error.
Problem seems (at first glance) to be Transport: it writes in one goroutine and sends
the correct error back on a channel (after marking the underlying conn as dead, so it
won't be reused), but meanwhile another goroutine is reading the response, and gets a
valid HTTP response from the server, so we return it.  (And because the server didn't
read the entire request body, it also notes that the connection is to be closed after
the response, since it can't reuse that TCP connection....)
We should also wait to know whether we finished writing the request before we return
success to from the RoundTripper.

@bancek
Copy link
Author

bancek commented Mar 12, 2014

Comment 3:

In transfer.go on line 56 if there is an error and n == 0 error is ignored and t.Body is
set to nil.
Attached patch fixes this problem.

Attachments:

  1. http_post_bug.patch (1095 bytes)

@bradfitz
Copy link
Contributor

Comment 4:

Good find. I'll fix it and add a test, unless you want to go through the contribution
process yourself. (We don't do patches on the bug tracker or mailing list).

@bancek
Copy link
Author

bancek commented Mar 12, 2014

Comment 5:

I already have a patch and will write some tests tomorrow. I can go through the process .

@bradfitz
Copy link
Contributor

Comment 6:

This issue was closed by revision 2701dad.

Status changed to Fixed.

@rsc rsc added this to the Go1.3 milestone Apr 14, 2015
@rsc rsc removed the release-go1.3 label Apr 14, 2015
@golang golang locked and limited conversation to collaborators Jun 25, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants