Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Errors from the redis library are ignored #12

Open
olivierkaisin opened this issue Dec 18, 2013 · 4 comments
Open

Errors from the redis library are ignored #12

olivierkaisin opened this issue Dec 18, 2013 · 4 comments

Comments

@olivierkaisin
Copy link

Hi!

We are currently using the library and we experience critical issues with it. Sometimes , due to network errors, our redis server becomes unreachable for a small amount of time, creating errors such as:

17 Dec 15:44:57 - Error: Redis connection to redisx.mdx2mz.0001.use1.cache.amazonaws.com:6379 failed - connect ETIMEDOUT
    at RedisClient.on_error (/var/www/app/node_modules/redis/index.js:189:24)
    at Socket.<anonymous> (/var/www/app/node_modules/redis/index.js:95:14)
    at Socket.EventEmitter.emit (events.js:95:17)
    at net.js:441:14

After some investigation we realised that most errors from the redis library are ignored and that there's no handler for the default error event of both this._redis and this._subscriber.

Also, in most callbacks, the error event is ignored, being an open door to unhandled exceptions.

i.e. In the following, when error is defined, clients isn't:

var notify = function(error, clients) {
  clients.forEach(function(clientId) {
    var queue = self._ns + '/clients/' + clientId + '/messages';

    self._server.debug('Queueing for client ?: ?', clientId, message);
    self._redis.rpush(queue, jsonMessage);
    self._redis.publish(self._messageChannel, clientId);

    self.clientExists(clientId, function(exists) {
      if (!exists) self._redis.del(queue);
    });
  });
};

Throwing TypeError: Cannot call method 'forEach' of undefined.

Hope we can help to get this fixed. Thanks!

@banks
Copy link

banks commented Oct 20, 2014

+1 this is preventing this being used in production for me. Myspace's sharded version seems to work better and supports unsharded use anyway so I will try that for now...

@fatso83
Copy link

fatso83 commented Sep 16, 2015

For anyone encountering this problem, and looking at the countless other forks that are out there, you should simply check out Gitter's fork (which is the PR in which #13 is based). The fork is often updated and regularly pulls in changes from this original branch as well.

This is how to set it up

// attach listeners for the various redis events that might arise, like 'error','end','connect','reconnecting'
function attachListeners (redisClientInstance, clientName) {
    redisClientInstance.on('error',function onRedisError (error) {
        logger.error(util.format('Redis (%s) reported error: %s', clientName, error.message));
    });
    // other events ...
});

redisClient = redis.createClient(redisConfig.port, redisConfig.host, redisConfig);
subscriberRedisClient = redis.createClient(redisConfig.port, redisConfig.host, redisConfig);

attachListeners(redisClient, 'faye redis client');
attachListeners(subscriberRedisClient, 'faye redis subscriber client');

var engineConfig = {
    type             : FayeRedisEngine,
    client           : redisClient,
    subscriberClient : subscriberRedisClient,
};

var nodeAdapterOptions = {
    mount   : config.faye.mount,
    timeout : config.faye.timeout,
    engine  : engineConfig
};

var bayeux = new faye.NodeAdapter(nodeAdapterOptions);

@dynajoe
Copy link

dynajoe commented Jan 19, 2017

@fatso83 Is the fork you mentioned still a viable option? Unhandled exceptions due to Redis connectivity in our node process has been a real pain.

@jcoglan Would you be willing to accept PR's to address this issue?

@fatso83
Copy link

fatso83 commented Jan 19, 2017

@joeandaverde, would not know. The GitterHq fork was fine until I left the project I was using it in a year ago. The PR for this is still sitting idle, so I think you have the answer to your second question :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants