question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Handle error when redis shuts down

See original GitHub issue

Hello, I have this little node server that communicates with a redis server, I just need some advice how I can make it so the nodejs app doesn’t crash when the redis server goes down. I need it to not crash and try and reconnect to redis, but I am not very experienced with using sockets so I am having quite the trouble, if somebody can help me I would be very greatful!


var express = require('express');
var app = express();
var server = require('http').createServer(app);
var socket = require('socket.io');
var redis = require("redis");
var redisAdapter = require('socket.io-redis');

server.listen(config.nodejs.port, function () {
    console.log('listening on ' + config.nodejs.port);
})

var io = socket.listen(server);
io.set("transports", ["xhr-polling", "websocket", "polling", "htmlfile"]);
io.adapter(redisAdapter({host: config.redis.address, port: config.redis.port}));
io.on('connection', function (client) {
    console.log('Client connected...');
    var sessionId = client.handshake.query.searchSessionId;
    client.join(sessionId);
    console.log('room ' + sessionId)
});


var searchResultQueue = redis.createClient({host: config.redis.address});
var blpopQueue = function () {
    searchResultQueue.blpop('socketio-search-result', 5, function (err, data) {
            blpopQueue();
            if (data) {
                var timestamp = data[1].substring(60, 73);
                var eventId = data[1].substring(14, 46);
                if (Date.now() - timestamp < searchResultTtl) {
                    console.log(eventId + ' ' + timestamp)
                    io.sockets.in(eventId).emit('flights/' + eventId, data[1]);
                } else {
                    console.log(eventId + ' skipped duo expired ttl')
                }
            }
        }
    )
}

blpopQueue();

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
ahmadzahabi1commented, Mar 13, 2020

I resolved this issue using this line: io.of(‘/’).adapter.on(‘error’, function(error){ console.log('error: ', error); });

1reaction
HosseinAghacommented, Mar 7, 2020

This still happens for me. I use ioredis as client. I’m listenning on error even of course. It logs the error and then crashes the server.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Handle error when redis shuts down · Issue #301 · socketio ...
I use ioredis as client. I'm listenning on error even of course. It logs the error and then crashes the server.
Read more >
Spring Redis Error Handle - Stack Overflow
I had the very same problem. I'm developing some data services against a database, using Redis as the cache store by way of...
Read more >
SHUTDOWN - Redis
Since Redis 7.0, the server waits for lagging replicas up to a configurable shutdown-timeout , by default 10 seconds, before shutting down. This...
Read more >
Error detection and handling with Redis - IBM Developer
This brings us to error detection and handling with Redis. How can you detect that the Redis server you were connected to has...
Read more >
redis server randomly stops without error - Google Groups
I've downgraded redis from 2.8 stable to 2.6 now. Whenever 2.8 crashes it did not delete the pid file however 2.6 deletes the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found