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/httputil: HTTP protocol errors using ReverseProxy #7010

Closed
cespare opened this issue Dec 23, 2013 · 6 comments
Closed

net/http/httputil: HTTP protocol errors using ReverseProxy #7010

cespare opened this issue Dec 23, 2013 · 6 comments
Milestone

Comments

@cespare
Copy link
Contributor

cespare commented Dec 23, 2013

In building an HTTP proxy I found that when I aggressively time out the backend requests
and have many client connections, I often get HTTP protocol errors and incorrect
responses.

This is reproducible using httputil.ReverseProxy as well. The code at
http://play.golang.org/p/ZQDr5M2NRx starts a simple server and proxy, and then uses 50
concurrent clients to make requests through the proxy. The server sleeps for 30ms before
responding and the proxy times the backend request out after 35ms, so many of the
requests cannot be handled in time.

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

1. Run the code at http://play.golang.org/p/ZQDr5M2NRx on your local computer

What is the expected output?

Besides the initial logging messages, the only error output I would expect are messages
like this:

    http: proxy error: net/http: timeout awaiting response headers

What do you see instead?

In addition to many timeout errors, I get messages like this:

    Unsolicited response received on idle HTTP channel starting with "H"; err=<nil>

and like this:

    Client: expected "hello", got: ""

That second error messages is one I'm printing out when the client makes what is
apparently a successful request to the proxy but gets back something other than
"hello", which is what the server is responding with.

Which compiler are you using (5g, 6g, 8g, gccgo)?

6g

Which operating system are you using?

Tested on darwin/amd64 and linux/amd64

Which version are you using?  (run 'go version')

go 1.2

Please provide any additional information below.

This came up in a similar context to issue #6995. The race detector didn't find any
issues in this code for me, though.
@cespare
Copy link
Contributor Author

cespare commented Dec 23, 2013

Comment 1:

Apologies; the "incorrect responses" I was seeing were simply the 500 errors the proxy
was returning when the backend request timed out. Here's the corrected repro code:
http://play.golang.org/p/_Hv6qogAHl
With the fixed code, I don't see any incorrect response bodies; however, the
"Unsolicited response" errors still exist.
Please change the title of this issue to read
"net/http/httputil: HTTP protocol errors using ReverseProxy"
or similar.
Thanks!

@rsc
Copy link
Contributor

rsc commented Mar 3, 2014

Comment 2:

Labels changed: added release-go1.3.

Owner changed to @bradfitz.

Status changed to Accepted.

@bradfitz
Copy link
Contributor

Comment 3:

Status changed to Started.

@gopherbot
Copy link

Comment 4:

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

@gopherbot
Copy link

Comment 5:

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

@bradfitz
Copy link
Contributor

Comment 6:

This issue was closed by revision 427a444.

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