I would like to enable the use of connection pooling via http.Agent
and https.Agent
in my node-http-proxy application. To do this I've established a secure agent, like so:
const secureAgent = new https.secureAgent({ keepAlive: true });
(I've elided the complementary http agent for brevity.)
I create a proxy server, as such:
const proxy = httpProxy.createProxyServer({});
Finally I proxy a request inside a Connect middleware like so:
proxy.web(req, res {
agent: isSecure ? secureAgent : agent,
target: ...,
secure: false,
});
This seems to work for most requests, but once every few minutes I see an error that looks like this:
{
"message": "Parse Error",
"stack": "Error: Parse Error\n at TLSSocket.socketOnData (_http_client.js:411:20)\n at emitOne (events.js:96:13)\n at TLSSocket.emit (events.js:191:7)\n at readableAddChunk (_stream_readable.js:178:18)\n at TLSSocket.Readable.push (_stream_readable.js:136:10)\n at TLSWrap.onread (net.js:560:20)",
"bytesParsed": 215,
"code": "HPE_INVALID_CONSTANT",
"__error_callsites": [
{},
{},
{},
{},
{},
{}
],
"level": "error",
"timestamp": "2017-04-18T17:34:09.735Z"
}
From some cursory reading, it seems HPE_INVALID_CONSTANT
manifests when the response is malformed. However, these responses are fine until the introduction of the secure agent.
Does anyone have any idea what's going on here or how I can fix it?
Notes: This error occurs on Node v7.9.0 in a Docker container via FROM node:7.9
. So far I've only observed this for HEAD
requests--there must be some reason for that.