Automattic / kue

Kue is a priority job queue backed by redis, built for node.js.
http://automattic.github.io/kue
MIT License
9.45k stars 865 forks source link

[createClientFactory] Trying to connect to localhost when using createClientFactory #882

Open petermekhaeil opened 8 years ago

petermekhaeil commented 8 years ago

Kue is trying to make a connect to localhost after I have successfully connected to a non-localhost redis server.

events.js:141
      throw er; // Unhandled 'error' event
      ^

Error: Redis connection to 127.0.0.1:6379 failed - connect ECONNREFUSED 127.0.0.1:6379
    at Object.exports._errnoException (util.js:870:11)
    at exports._exceptionWithHostPort (util.js:893:20)
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1063:14)

This happens after I successfully connect to my redis server (which does not sit on localhost).

My dependencies:

├── kue@0.10.5
├── kue-ui@0.1.0
├── redis@2.6.0-1

I am using node-redis has my redisClient:


    app.redisClient = redis.createClient(config.redis.port, config.redis.host);
    app.jobs = kue.createQueue({
        redis: {
            createClientFactory: function () {
                return app.redisClient;
            }
        },
        disableSearch: true
    });

Is Kue trying to make another connection for another feature that I am not across?

Cheers, Peter

behrad commented 8 years ago

in createClientFactory You should return a configured client instance not the factory method app.redisClient

petermekhaeil commented 8 years ago

Sorry, I missed that in the initial post.

app.redisClient = redis.createClient(config.redis.port, config.redis.host);

I know connection is successful because I logged it:

app.redisClient.on('connect', function () {
    console.info('successful connection to redis server');
});

But soon right after I get the error mentioned above

successful connection to redis server
events.js:141
      throw er; // Unhandled 'error' event
      ^

Error: Redis connection to 127.0.0.1:6379 failed - connect ECONNREFUSED 127.0.0.1:6379
    at Object.exports._errnoException (util.js:870:11)
    at exports._exceptionWithHostPort (util.js:893:20)
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1063:14)
petermekhaeil commented 8 years ago

I solved it by using the default redis client from Kue

    app.jobs = kue.createQueue({
        prefix: config.redis.prefix,
        redis: {
            port: config.redis.port,
            host: config.redis.host
        }
    });
behrad commented 8 years ago

Then I shall rename the topic if you don't mind

retpolanne commented 5 years ago

Hello. I had the same issue with an app. We had attached a debugger and, when stepping through the functions, kue resolves the name just fine. However, when we let it run without stepping, it tries to connect to 127.0.0.1 instead.

We saw that, when we call createQueue during the step through, the Queue singleton already exists. Is that expected?

Does this function have some kind of callback?