Search code examples
azureredisazure-web-app-serviceazure-redis-cache

ioredis ETIMEDOUT from Azure App Service, but works fine locally, IP's added to firewall


I have an Azure Redis Cache which I'm currently testing. It is not being used/nothing is connecting to it besides what I'm trying to do now. It is part of the most basic C0 plan.

The issue is, once deployed as part of an Azure App Service it will constantly throw out:

[ioredis] Unhandled error event: Error: connect ETIMEDOUT
     at TLSSocket. (/home/site/wwwroot/node_modules/ioredis/built/redis/index.js:282:31)
     at Object.onceWrapper (events.js:273:13)
     at TLSSocket.emit (events.js:182:13)
     at TLSSocket.Socket._onTimeout (net.js:449:8)
     at ontimeout (timers.js:425:11)
     at tryOnTimeout (timers.js:289:5)
     at listOnTimeout (timers.js:252:5)
     at Timer.processTimers (timers.js:212:10)

All is well and works fine if I run the app locally. I have added both my local IP and the app service's IP to the firewall as well.

My configuration is:

 host: this.get('REDIS_HOST'),
      port: 6380,
      password: this.get('REDIS_PRIMARY_KEY'),
      tls: true as any,
      connectTimeout: 1000,

and

import * as redis from 'ioredis';
redis: redis.Redis;

in constructor: 

this.redis = new redis(this.configService.getRedis());

Solution

  • I tried to reproduce your issue on my environment, then I found it seems to be caused by the connectTimeout value is too short and shorter than the default value 10000 of connectTimeout defined in export const DEFAULT_REDIS_OPTIONS: IRedisOptions as below.

    export const DEFAULT_REDIS_OPTIONS: IRedisOptions = {
      // Connection
      port: 6379,
      host: "localhost",
      family: 4,
      connectTimeout: 10000,
      //.....
    }
    

    If I set the connectTimeout value with 1000 or even 100, I would get the same issue with yours on my environment, as the figure below.

    enter image description here

    So please try to remove the connectTimeout property and use the default value, or just set a timeout value longer than the default one.