Implemented real-time services with nodejs and socket.io.
socket.io connection occurs in and out of 100.
If you look at the socket being used in the terminal
cat /proc/20807/net/sockstat
It's well over 100 and it keeps increasing over time. So, the maximum number of file descriptor assignments per process was exceeded, and eventually, Socket connection is no longer possible, and there is a problem that you need to restart app.js.
How can we solve this problem?
node.js socket.io
I'm having the same problem. First of all, what kind of environment is the client? In my case, the client is Android, but even if it ends normally on Android, the socket connection does not end normally. I couldn't check if this was the problem with the library I used or Android. I checked that the connection was disconnected immediately when I finished with System.exit(0) on Android, so the trash connection disappeared a lot, but it hasn't been completely resolved, so I'm avoiding the problem by restarting node.js app every time. Currently, we are operating up to 2000 Dongjeop without any problems with the service.
Nodes are basically designed to withstand many connections, so there is usually no problem if they are cleaned up a little later.
But dealing with the problem with a restart is a stopgap, so you'll definitely have a problem again.
(It would also be a big problem to lose all connections of users who are accessing every restart.)
First of all, you have to check on the code where the socket is not being organized by terminating the connection to the client-server, and
Next, as shown in the answer above, you should send a ping periodically to handle the socket that is not organized.
If the number of max open files is exceeded, tuning the Linux kernel parameters is possible to some extent.
Please change the settings by searching for the link below or ulimit related content.
© 2024 OneMinuteCode. All rights reserved.