2

In my project, I'm using (socket.io - 2.3.0) & (socket.io-redis - 5.2.0) for data broadcasting between servers. In that scenario, I'm having the redis timeout issue from time to time, and I'm not sure why. In my server I just run a single node process, and I use Redis to store data and share it with other connections. Is it correct that I use almost 5 dbs in redis out of 15? In production, I encountered this problem more than ten times in a single day. Please assist us in resolving this issue.

Stack Trace:

Error: timeout reached while waiting for clients response
    at Timeout._onTimeout (/var/www/html/project/node_modules/socket.io-redis/index.js:485:48)
    at listOnTimeout (internal/timers.js:555:17)
    at processTimers (internal/timers.js:498:7)

Here it's my node entry point.

var port = 12300;
var io = require('socket.io')(port);
var redis = require('redis');
const redis_adap = require("socket.io-redis");
io.adapter(redis_adap({
    host: '127.0.0.1',
    port: 6379,
requestsTimeout: 5000, // i tried upto 20000 but still the issue is occured
}));

io.on('connection', function(socket) {

    var player = new Player();
    var Redis = new redis();
    var roomId;
    player.id = socket.id;

    socket.on('ping', function() {
        socket.emit('pong');
    });

    socket.on('message', function(data) {
        let _messageIndex = data.e;
        let _id = player.id;
        let returnData = {
            i: _id,
            e: _messageIndex
        }
        socket.broadcast.to(player.roomid).emit('message', returnData);
    });

    socket.on('UpdateHorn', function() {
        let _id = player.id;
        let returnData = {
            i: _id
        }
        socket.broadcast.to(player.roomid).emit('UpdateHorn', returnData);
    })

    socket.on('UpdateTiles', function(data) {
        let returnData = {
            t: data.t
        }
        socket.broadcast.to(player.roomid).emit('UpdateTiles', returnData);
    });

    socket.on('getLobbyDetails', function() {
        socket.emit('getLobbyDetails', { lobby: CONFIG.getLobbyDetails() });
    })
})
Annamalai
  • 109
  • 2
  • 12

0 Answers0