javascript - file descriptor number increases when using websocket and nodejs -
i using websocket library ws npm @ 5001 , nodejs port 80 communication.
my issue on period of time number of file descriptors increases results more ram consumption.
below code.
var sockets = []; //used publish url var app = https.createserver(options, function(req, response){ log.debug("connection:"+ req.url); var path = url.parse(req.url,true).pathname; log.debug('path:'+path); //response.writehead(200,{ 'content-type': 'text/html' }); switch(path){ case '/push': client.send(user_message); response.writehead(200,{ 'content-type': 'text/json' }); response.write(json.stringify({ 'userids': valid_users})); break; } // send html headers , message response.end(''); }); app.listen(config.websocket_port); var websocketserver = require('ws').server , wss = new websocketserver({ server: app } ); wss.on('connection', function(ws) { ws.on('message', function(userid) { ws.userid = userid; if(sockets[userid]){ delete sockets[userid]; } sockets[userid] = ws; log.debug("userid: " + userid.tostring() + " connected"); }); ws.on('close', function(){ log.debug(" socket userid closed ", ws.userid); var userid = ws.userid; if(sockets[userid] == ws){ sockets[userid] = null; } delete sockets[userid]; }); ws.on('error', function(){ log.debug(" socket error "); }); });
can ?
Comments
Post a Comment