Last active
August 29, 2015 14:06
-
-
Save migounette/e4cc054adb27017c0457 to your computer and use it in GitHub Desktop.
fd leaks on Linux system with socket.io 1.1.x and node 0.11.14
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
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0" | |
var socketio = require('socket.io-client'); | |
var totalCnx = 10; | |
var countCnx = 0; | |
var countCnxClose = 0; | |
var timerId = setInterval(function() { | |
if (countCnx++ > totalCnx) { | |
clearTimeout(timerId); | |
} | |
else { | |
var client = socketio.connect( | |
// Replace with your IP | |
'https://16.16.93.201:4443/signaling', | |
{ | |
'forceNew' : true | |
} | |
); | |
client.on('connect', function(obj){ | |
console.log('Connected #' + countCnx); | |
client.emit("gateway", {"message": "booohhh" }); | |
client.on('message', function(data) { | |
console.log(data); | |
client.close(); | |
}); | |
client.on('disconnect', function(){ | |
++countCnxClose; | |
console.log('Bye... Closed #' + countCnxClose); | |
}); | |
}); | |
} | |
}, 100); | |
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
{ | |
"name": "socket.io.issue", | |
"description": "Check socket.io socket close issue", | |
"version": "0.0.0", | |
"author": "migounette <[email protected]>", | |
"engines": { | |
"node": ">= 0.10.0" | |
}, | |
"scripts": { | |
}, | |
"main": "index.js", | |
"dependencies": { | |
"express": "~4", | |
"socket.io": "~1", | |
"socket.io-client": "~1", | |
"body-parser": "~1" | |
}, | |
"keywords": [], | |
"repository": "", | |
"license": "BSD", | |
"devDependencies": { | |
} | |
} |
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 fs = require('fs'); | |
var express = require('express'); // call express | |
var app = express(); // define our app using express | |
var bodyParser = require('body-parser'); | |
var socketIO = require('socket.io'); | |
// configure app to use bodyParser() | |
// this will let us get the data from a POST | |
app.use(bodyParser.urlencoded({ extended: true })); | |
app.use(bodyParser.json()); | |
var wssPort = 4443; // set our port | |
// ROUTES FOR OUR API | |
// ============================================================================= | |
var router = express.Router(); // get an instance of the express Router | |
var options = { | |
key: fs.readFileSync('cert/key.pem'), | |
cert: fs.readFileSync('cert/cert-self-signed.pem') | |
}; | |
app.use('/', router); | |
var wssServer = require('https').createServer(options, app).listen(wssPort, function() { | |
console.log('WSS Server listening on port [' + wssPort + ']'); | |
}); | |
var sioInstance = socketIO.listen(wssServer); | |
function checkCredentials(signaling, socket, next) { | |
process.nextTick(function() { | |
next(); | |
}); | |
} | |
var cnx = 0; | |
sioInstance.of('/signaling') | |
.use(function(socket, next) { | |
checkCredentials(true, socket, next); | |
}) | |
.on('connection', function(socket) { | |
console.log('Total Cnx #: ' + ++cnx); | |
socket.on('disconnect', function() { | |
console.log('Disconnect'); | |
}); | |
// | |
// Add handler to 'gateway' scope | |
// | |
socket.on('gateway', function(message) { | |
// | |
// Redirect the event to the event relay internals | |
// | |
try { | |
socket.emit('message', { 'message' : 'Hi gringo....' }); | |
} catch (ex) { | |
console.log(ex); | |
} | |
}); | |
}); | |
setInterval(function() { | |
if (global.gc) { | |
console.log('!!!!!!!!!!!!!! GC !!!!!!!!!!!!!!!!') | |
global.gc(); | |
} | |
}, 2*1000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Crash code, no realistic but show a fd close issue...
Run server.js (node server.js)
It opens the port 4443 - wss port
The client connects to 4443 and do some sessions...
Check on the server side : lsof -p of the node process
Do a full run and the cut the client run in the middle, this operation shows the problem.
You can see it only if wss is here (no sure) but more preditictable
Confirmed on Ubuntu 14.x and RedHat 6.5
I have a "can't identify protocol"
Result:
node 10069 root 10u IPv6 7874332 0t0 TCP *:3443 (LISTEN)
node 10069 root 11u IPv6 7874333 0t0 TCP *:4000 (LISTEN)
node 10069 root 12u IPv6 7874334 0t0 TCP *:4443 (LISTEN)
node 10069 root 13u CHR 5,0 0t0 1037 /dev/tty
node 10069 root 14u CHR 5,0 0t0 1037 /dev/tty
node 10069 root 15u IPv6 7878334 0t0 TCP nv02.gre.hp.com:4443->cbecker13.emea.hpqcorp.net:13520 (CLOSE_WAIT)
node 10069 root 16u IPv6 7880325 0t0 TCP nv02.gre.hp.com:4443->cbecker13.emea.hpqcorp.net:14050 (ESTABLISHED)
node 10069 root 17u IPv6 7883912 0t0 TCP nv02.gre.hp.com:4443->cbecker13.emea.hpqcorp.net:14053 (ESTABLISHED)
node 10069 root 18u IPv6 7879275 0t0 TCP nv02.gre.hp.com:4443->cbecker13.emea.hpqcorp.net:14051 (ESTABLISHED)
node 10069 root 19u IPv6 7878287 0t0 TCP nv02.gre.hp.com:4443->cbecker13.emea.hpqcorp.net:13314 (CLOSE_WAIT)
node 10069 root 20u sock 0,7 0t0 7874366 can't identify protocol
node 10069 root 21u IPv6 7880327 0t0 TCP nv02.gre.hp.com:4443->cbecker13.emea.hpqcorp.net:14052 (ESTABLISHED)
node 10069 root 22u sock 0,7 0t0 7877179 can't identify protocol