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() });
    })
})
1
  • 1
    I have the same problem but with latest redis and socket.io v4 Commented Feb 12, 2022 at 20:05

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.