Created
April 30, 2012 23:18
-
-
Save jkorycki/2563580 to your computer and use it in GitHub Desktop.
Small repro of TCP keep alive flood
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
environment: | |
node for Windows v.0.6.8 | |
socket.io v. 0.9.6 | |
http-proxy v. 0.8.0 | |
browser: chrome (this will force the use of websockets) | |
test: | |
- run server: node server | |
- load client into chrome using http://host:8080/client.html | |
- observe in wireshark a flood of TCP keep alives | |
- bypass http-proxy by setting the port in client.html to 8081, reload client | |
- observe no TCP keep alives in wireshark | |
When the server is run on Mac, no TCP keep alives are noticed, even when going through http-proxy. | |
The problem is specific to websockets. When long-poll transport is forced in socket.io, no TCP keep alives are used when going through http-proxy, including when the server is on Windows. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title>socket.io client</title> | |
<script src="/socket.io/socket.io.js"></script> | |
<script> | |
var port = 8080; | |
//var port = 8081; | |
var socketioUrl = 'http://' + window.location.hostname + ':' + port; | |
console.log( 'socketioUrl: ' + socketioUrl); | |
var socket = io.connect( socketioUrl); | |
socket.on('hello', function (data) { | |
console.log(data); | |
}); | |
</script> | |
</head> | |
<body> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var socketio = require( 'socket.io'), httpProxy = require('http-proxy'), http = require('http'), | |
fs = require('fs'); | |
var httpServer = http.createServer( function( request, response) { | |
if( request.url === '/client.html') { | |
fs.readFile('client.html', function(err, data) { | |
response.end(data); | |
}); | |
} | |
}).listen( 8081); | |
var io = socketio.listen( httpServer); | |
io.sockets.on( 'connection', function( socket) { | |
console.log( 'connection'); | |
socket.on( 'disconnect', function() { | |
console.log( 'disconnect') | |
}); | |
socket.emit( 'hello', 'hello world'); | |
}); | |
var proxy = new httpProxy.RoutingProxy(); | |
proxyHttpServer = http.createServer( function(request, response) { | |
console.log('forwarding ' + request.url); | |
proxy.proxyRequest(request, response, {host: 'localhost', port: 8081}); | |
}); | |
proxyHttpServer.on('upgrade', function(request, socket, head) { | |
console.log('upgrade ' + request.url); | |
proxy.proxyWebSocketRequest(request, socket, head, {host: 'localhost', port: 8081}); | |
}); | |
proxyHttpServer.listen( 8080); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment