redis / ioredis

🚀 A robust, performance-focused, and full-featured Redis client for Node.js.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ioredis not able to find the attached error eventlistener and prints the error on console in case of timeout, EHOSTUNREACH and ECONNREFUSED

amanjain7838 opened this issue · comments

Silent emit is not working for all type of error. I added the error event listener to listen the errors and it seems to working fine for the sentinel and other type of errors. But it finds no event listener attached for redis related errors and goes to the second "if" condition on redis.ts and print "[ioredis] Unhandled error event".

image

I tried to debug the source of errorhandler method to catch the error and got to know that is only happening for the error cases when connection is completely down. In that case nodejs try to resolve the host but fails to resolve it and emit the error. As the connecttimeout is of default 10 sec. It finds no stream is connected and then calls the error handler on line:: 264 . That later checks for the eventlistener's length and finds no error event attached leading to print the "[ioredis] Unhandled error event" on console.

Steps to reproduce:

  1. Start the nodejs server and let the ioredis connect to sentinel servers.
  2. Once the connect event is triggered, bring down the sentinel and redis servers.
  3. After 60 sec ioredis will print the "Unhandled error event".

Code snippet:

(async () => {
    cache = new ioredis({
        sentinels: redis_config.sentinelsHost,
        name: redis_config.client_name,
        sentinelPassword: sentinel_redis_pw,
        password: redis_pw,
        failoverDetector:true,
        enableOfflineQueue:false,
        commandTimeout: redis_config.commandTimeout,
        retryStrategy: retryDelay, 
        sentinelRetryStrategy: retryDelay,
        showFriendlyErrorStack: true
    })

    cache.on("connect", () => {
        console.log("Connected  to Redis");
    }); 

    cache.on("error", err => {
        let error = err && err.message ? err.message : "Redis connection error";
        logger.info("Redis error : " + JSON.stringify(error));
    }); 
    })();

Hi @luin, Any suggestion on this?

Same here. I'm using ^5.3.2