Node.js with Socket.IO - Unexpected 'Socket Disconnected' scenarios During High Load
I'm following best practices but This might be a silly question, but I'm working on a project and hit a roadblock... I'm working on a project and hit a roadblock. I'm working with issues with my Node.js application using Socket.IO where clients are randomly getting disconnected during periods of high load. I am using Node.js version 16.x and Socket.IO version 4.0. The disconnects seem to happen unpredictably when there are multiple clients trying to connect simultaneously. Hereβs a simplified version of my server setup: ```javascript const express = require('express'); const http = require('http'); const { Server } = require('socket.io'); const app = express(); const server = http.createServer(app); const io = new Server(server); io.on('connection', (socket) => { console.log('a user connected'); socket.on('disconnect', (reason) => { console.log(`User disconnected: ${reason}`); }); }); server.listen(3000, () => { console.log('listening on *:3000'); }); ``` I've tried increasing the `pingInterval` and `pingTimeout` options in Socket.IO, but it hasn't resolved the scenario. Hereβs how I've adjusted those settings: ```javascript const io = new Server(server, { pingInterval: 25000, pingTimeout: 60000, }); ``` Despite these changes, I still see clients getting disconnected with the message `Socket Disconnected: transport close`. I've also checked the network conditions and there doesn't appear to be any important latency. Additionally, I'm using a Redis adapter for scaling, which is configured as follows: ```javascript const { createAdapter } = require('socket.io-redis'); const redisAdapter = createAdapter({ host: 'localhost', port: 6379 }); io.adapter(redisAdapter); ``` Could there be a question with the Redis setup or Socket.IO configuration under load? Any insights or debugging tips would be greatly appreciated. This is part of a larger service I'm building. Has anyone else encountered this? This is part of a larger application I'm building. I'm coming from a different tech stack and learning Javascript. Thanks, I really appreciate it! The project is a microservice built with Javascript. What am I doing wrong?