redis / ioredis

🚀 A robust, performance-focused, and full-featured Redis client for Node.js.
MIT License
14.06k stars 1.19k forks source link

Connection Drops with rediss:// URLs #1889

Closed ilshm closed 2 months ago

ilshm commented 2 months ago

When using rediss:// URLs to connect to Redis instances hosted on DigitalOcean and Aiven servers in my Node.js application with the ioredis client library, I'm experiencing connection drops. However, when using RedisLabs servers with redis:// URLs (as they don't seem to support rediss://), the connection works fine.

After a period of server inactivity (approximately 5-10 minutes), I observe the following logs:

Redis connection closed
Connected to Redis
Redis connection closed
Connected to Redis

Environment:

ioredis version: 5.4.1 Node.js version: v20.12.1 Operating System: Ubuntu 22.04 (Digital Ocean Droplet: 8 GB Memory / 4 AMD vCPUs / 160 GB Disk / FRA1)

Steps to Reproduce:

const Redis = require('ioredis')

const redis = new Redis(process.env.REDIS_URL)

redis.on('connect', () => {
    console.log('Connected to Redis')
})

redis.on('close', () => {
    console.log('Redis connection closed')
})

redis.on('error', (err) => {
    console.error('Redis connection error:', err)
})

module.exports = redis
eazylaykzy commented 2 months ago

@ilyabumblebee that's a normal thing with most of the cloud hosted Redis offering, it disconnect after 300ms, you can get around that by implementing a ping to your Redis at intervals, probably ping it in your /healthcheck route.

ilshm commented 2 months ago

Thanks, that's actually not too annoying. I was just curious about why that happens.