各位有使用socket.io出现内存泄露问题吗,我的用法是一个cluster启动一个子进程socket.io来接收前端连接,提供实时消息服务
框架是这样的 /**
if (cluster.isMaster) { for (var i = 0; i < 1; ++i) { cluster.fork();
cluster.on('exit', function(worker, code, signal) {
log.error('socket worker ' + worker.process.pid + ' died, code is ' + code + ", signal is " + signal, log.getFileNameAndLineNum(__filename));
cluster.fork();
email.sendMail('socket worker ' + worker.process.pid + ' died');
});
cluster.on('listening', function(worker, address) {
log.info("A socket worker with pid#" + worker.process.pid + " is now listening to:" + address.port,
log.getFileNameAndLineNum(__filename));
});
}
} else {
process.on('uncaughtException', function(err) {
log.error('SOCKET SERVER Caught exception: ' + err.stack, log.getFileNameAndLineNum(__filename));
email.sendMail('SOCKET SERVER Caught exception: ' + err.stack);
});
startSocketServer();
}
function startSocketServer() {
var io = require('socket.io').listen(socketPort);
log.logPrint(config.logLevel.DEBUG, "start listen socket");
io.sockets.on('connection', function(socket) {
log.logPrint(config.logLevel.DEBUG, process.pid + " get the socket:" + socket.id);
//do some event
socket.on('disconnect', function(msg) {
log.debug(msg, log.getFileNameAndLineNum(__filename));
//delete io.sockets.sockets[socket.id];
//delete socket;
//socket.close();
});
});
}
我的测试客户端每次建立一个连接,就会消耗内存,但是每次disconnect之后,内存不会释放掉,就这样一直增长下去,直到这个进程内存耗用过大被系统杀掉
是否在socket.io执行disconnect事件的时候需要做一些处理???