Node.js and Socket.io do not respond

I have a relatively simple chat type application running on Node.js and Socket.io. The node server transfers chat data from the Minecraft server, and then transfers it to any clients connected to the website using Socket.io. A working demo of the system can be found here: standardsurvival.com/chat .

It works fine, for the most part, but from time to time the node server stops responding and active connections die soon. At this time, the process will begin to consume 100% of the processor, but the memory always remains relatively constant, so I doubt the memory leak.

It was very difficult, because I could not reproduce the problem sequentially enough to find out what the problem was, and I did not know where to look. I set up loops and commented on various parts of the pipeline between the node server and the website to try to determine what might cause it. Not lucky yet.

The code for this system can be found here and here .

Any ideas?

+4
source share
1 answer

Well, I found out what the problem is. The library I use opened net.Sockets for standard HTTP requests to the Minecraft server, but never closed them. Apparently, the end event was never raised when the request completed. Thus, in the end, all available file descriptors for the process were used up and caused new requests that were not fully executed, which caused the server to stop responding. I would have known about this earlier if I had registered this error. Lesson learned.

I added a timeout for all sockets to fix this, at least temporarily. Now the server works for several days without any one problem :)

0
source

Source: https://habr.com/ru/post/1481100/


All Articles