I have a Django app running on Fly. I am using upstash redis as a cache and message broker for a celery worker process.
The problem is, no matter what I try I seem to get seemingly random connection errors - usually a handful every hour. The error message I get is: ConnectionError: Connection closed by server.. Retrying always seems to work. This happens randomly on different operations that involve redis. Here is a graph of the errors in the last day:
This ranges from 0 to 5 per hour.
I’ve read lots of threads on this topic on the forum but haven’t found a solution. Things I have tried:
Upgrading my app to v2.
Upgrading to a paid redis instance.
Adding a ping/heartbeat function to my app to hit redis every 5 minutes.
Appending /0 to my connection string.
Any other suggestions on how I can resolve this? Is Django + upstash just inherently not reliable on fly?
Just to update on this, I’ve now gone the route of bypassing upstash entirely and setting up my own Redis instance. Since cutting over have seen no new errors:
Documenting the steps I took in case anyone else finds this:
I’ve also encountered this issue the last few weeks. I’m using Redis-py + FastAPI with Upstash, so its definitely not just a Django issue. Most likely the Fly proxy or the Upstash instance has some sort of disconnect rule after a certain amount of time. It would be good if someone from the Fly/Upstash team could take a look at why its happening, and/or suggest ways of handling these exceptions, as it seems intermittent. Sometimes my cache pings get through, and then sometimes they result in:
raise ConnectionError(SERVER_CLOSED_CONNECTION_ERROR)
redis.exceptions.ConnectionError: Connection closed by server.
I’ve also been experiencing connection errors with Sidekiq. They started occurring in July. Before that I hadn’t experienced any issues. I would expect more stability from a paid offering.