socket.io icon indicating copy to clipboard operation
socket.io copied to clipboard

Socket.io pm2 on shutdown doesnt closes sockets

Open MyMomSaysIAmSpecial opened this issue 10 years ago • 5 comments

This issue follows https://github.com/Unitech/pm2/issues/2508 The problem is if i restart or reload socket.io server via pm2, i still have many sockets left online (as far as i understood), so as a result i have cpu load and memory spikes.

Also as a precursor of this problem, no matter which mode (fork or cluster) my server is running, my active sockets count is growing (without sharp jumps, for example: 4000, 3995, 4010, 4005, 4020, but still constantly) with time, what needs more and more memory and as a result i have memory leak?

MyMomSaysIAmSpecial avatar Nov 11 '16 15:11 MyMomSaysIAmSpecial

About connection count what is rising constantly - it's not pm2 problem, i turned down nginx, pm2, cluster and left only one instance which i run on pure node.js with "node server.js" command without any parameters. So who will read this in future, my connection count problem is NOT because of PM2.

Problem is mobile clients, they ignore socket.io connection/reconnection settings, and despite server was offline for 3 days, they still pingin it, and then server goes online, they reconnects. So if port was public once, and there is still open clients with this port, you will have my situation.

MyMomSaysIAmSpecial avatar Nov 14 '16 10:11 MyMomSaysIAmSpecial

I am a beautiful person who is a great day and night

PatcharinMakkarjang avatar Nov 14 '16 18:11 PatcharinMakkarjang

@Nerfair which socket.io client do the mobile clients use? socket.io-client? Or the native ones (Android/iOS)?

darrachequesne avatar Nov 15 '16 06:11 darrachequesne

@darrachequesne I am not sure i understood right but it's standart

<script src="https://cdn.socket.io/socket.io-1.4.5.js"></script>
<script>
    var socket = io('http://localhost');
    socket.on('message', function (data) {
        console.log(data);
    });
</script>

and on server side it is

sio = require('socket.io')

MyMomSaysIAmSpecial avatar Nov 17 '16 09:11 MyMomSaysIAmSpecial

Closed due to inactivity, please reopen if needed.

darrachequesne avatar Feb 18 '21 14:02 darrachequesne