redis / ioredis

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

Not always detecting closed connections on Fly.io #1706

Open thewilkybarkid opened 1 year ago

thewilkybarkid commented 1 year ago

This follows on from: https://community.fly.io/t/upstash-redis-and-could-not-send-http-request-to-instance-connection-error-timed-out-logs/10104

The Redis service on Fly.io (provided by Upstash) closed idled connections after an hour, but ioredis didn't always recognise it. (They increased it to a day to reduce the number of errors. I've added a ping to our app's health check, which keeps the connection alive.)

I added logging for the various events ioredis emits and could see that sometimes it would recognise the connection had closed and reconnect, but sometimes it didn't. When the connection was then used, any command would just time out.

There are a few things here:

luin commented 1 year ago

Thanks for reaching out! It would be helpful if we can reproduce the issue locally. Not sure if the keepAlive option works for the issue.

A regular ping setting would be useful to keep connections alive.

It's easy to implement this in app code so that's a major reason why it's not built in.

jasonkuhrt commented 1 year ago

@luin what is the documentation for keepAlive?

CleanShot 2023-01-30 at 11 03 20@2x
luin commented 1 year ago

It's the native one supported by Node.js: https://nodejs.org/api/net.html