Skip to content


ECONNRESET when POSTing to a proxy through connect server #496

robsquires opened this Issue · 7 comments

5 participants


We have written a proxy to authenticate http requests to several servers, following the recommended design pattern:

We are using connect middleware within this proxy to process cookie authentication and relay this internally to the servers via queryString parameters. The middleware in use is:


Everything works ok for GET requests.

I'm having trouble with POST requests. Originally the requests were just hanging but I was able to resolve that using the httpProxy.buffer(req).

During a POST response the request is forwarded to the backend, the backend responds and then the proxy throws { [Error: socket hang up] code: 'ECONNRESET' }.

I've done some digging around.

  1. This does not happen with node 0.10.x (but we're proxying websockets as well so need 0.8)

  2. This doesn't happen when we proxy without connect middleware processing the request

Can anyone offer any advice?

connect : ~2.9.0
http-proxy : ~0.8.7
node : 0.8.24

Many thanks


The connect.session appears to be the culprit...not sure why :(


This is being caused by utils.pause(req); within connect.session.

Any ideas why this might be messing up the response when handled by the proxy?


I think I've got to the bottom of this. I was buffering the request object further up the middleware chain than the connect session. The session calls pause.resume after the rest of the middleware, including the proxy, leading to further data events being emitted. I discovered this by logging inside the data listener in the proxy.

By re-ordering my middleware, buffering after the session everything seems to work OK.

Does anyone have any advice on this solution?



FWIW, I'm having the same symptom (POSTs fail when proxied, everything else works fine), but I'm not buffering.


This looks like it is related to issue #180 and #326 though those use an older version of http-proxy. It certainly would be nice if http-proxy was changed to work without having to reorder the middleware. :-)


I'm also having this issue.

nodejitsu member

@djmccormick I will be closing this as it is an old issue but the answer has to do with having any middleware that buffers the request data when attempting to proxy. The solution is to create a separate a proxy middleware to handle the intended routes before hitting that middlware OR create a separate router altogether that has its own middleware chain that does not parse the request.

Hope this helps. If you cannot figure it out, open a new issue with a complete reproducible code sample

@jcrugzz jcrugzz closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.