Uncatchable error when upstream server returns malformed HTTP response
Created by: jcheng5
We have a production app that uses node-http-proxy running in front of some (admittedly sketchy) webservers running R code. (http://www.r-project.org) We've been seeing our node process crash several times a day. It turns out to be a bug in node with a known workaround but node-http-proxy prevents us from using that workaround.
There was a bug in the R code that caused the Content-Length to be inaccurately reported upstream. The issue here though is that the content-length caused Node issue 3776 to come into effect; when an http request is made and the node http parser encounters an error, that error is emitted on the socket/connection object. In the case of node-http-proxy's proxyRequest method, the caller can never catch that error, and therefore the node process exits. Obviously we would rather gracefully deal with the error than have the process exit.
Issue 3776 was fixed in Node 0.9.2 but since Node 0.8.15 is still the latest stable version, it would be great if this bug could be worked around in node-http-proxy as well. I'm about to submit a pull request that approximates the Node 0.9.2 fix.