Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Flood of TCP keep-alives when proxying websocket #237

Open
jkorycki opened this Issue · 6 comments

3 participants

@jkorycki

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

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?

Thanks!

@jkorycki

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

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

Just post a link to the gist here.

@jkorycki

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

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

Any thoughts on this issue by anyone?

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.