Flood of TCP keep-alives when proxying websocket #237

jkorycki opened this Issue Apr 27, 2012 · 7 comments


None yet
4 participants

Setup: socket.io client in chrome browser connects to http-proxy which forwards to socket.io server. The connection is setup using websocket, and functionally everything works well. http-proxy version 0.8.0, socket.io version 0.9.6, node version 0.6.8.

Problem: http-proxy sends a flood of TCP keep-alives to the client, at a rate of about 30 per sec (!). This was confirmed using wireshark. In the test, the websocket connection is kept open but it is otherwise completely idle, we send no messages over it.

Attempted fix: proxyHttpServer.on('upgrade', function(request, socket, head) { socket.setKeepAlive( false); ...}. Unfortunately this has no effect, and the keep-alives keep on getting sent at high rate.


Marak commented Apr 27, 2012

That doesn't sound good. I have a feeling this might be due to something specific in your environment.

Could you possibly post your logs or a minimal reproducible case of code we can run?


I created a very simple repro sample. Can you let me know where to post it?

Note: the issue occurs on Windows, using node.exe. It works fine on Unix (tested on Mac).


Marak commented Apr 30, 2012

Just windows! Hrmm....I wonder if this could be a core issue.

Just post a link to the gist here.

Gist link: https://gist.github.com/2563580

This problem disappears when http-proxy is bypassed, i.e. client connects directly to socket.io. I contacted also node developers at Microsoft, and got the following response:

"This sounds like a Windows-specific issue with http-proxy. By default, we don’t send keep-alive packets in node core. Most likely http-proxy enables keep-alive (using http://nodejs.org/api/net.html#net_socket_setkeepalive_enable_initialdelay). "

jkorycki commented May 1, 2012

I did dome more digging. The problem is with setting the keepalive on a socket in proxyWebSocketRequest() in a helper function _socket(). On Windows this results in the keepalive flooding, on Mac no such issue. For the purposes of my application, which already has a heartbeat in socket.io layer, the fix is to reset the keepalive after proxyWebSocketRequest():

proxyHttpServer.on('upgrade', function(request, socket, head) {
logger.debug('upgrade ' + request.url);
proxy.proxyWebSocketRequest(request, socket, head, getRoutingTarget(request));
socket.setKeepAlive(false, 0);

I think this is something that can still be improved in http-proxy, maybe in the documentation, since someone else that makes use of http-proxy on Windows in conjunction with websocket will surely run into this problem again.

itay commented May 7, 2012

Any thoughts on this issue by anyone?


jcrugzz commented Oct 30, 2015

No longer relevant, closing due to old age.

@jcrugzz jcrugzz closed this Oct 30, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment