Upstash Redis - Connection lost (ECONNRESET) (Redis::ConnectionError

upstash redis is designed for serverless clients which makes it a good match for Rails caching but isn’t quite as good of a match for web sockets. The patch gets by, but perhaps installing redis in your own image is a better solution.

If you generated your Dockerfile with a fairly recent flyctl launch, I can walk you through the steps:

Add ruby-foreman redis-server to DEPLOY_PACKAGES.

Add the following some place after the last apt-get install:

# configure redis
RUN sed -i 's/^daemonize yes/daemonize no/' /etc/redis/redis.conf &&\
  sed -i 's/^bind/# bind/' /etc/redis/redis.conf &&\
  sed -i 's/^protected-mode yes/protected-mode no/' /etc/redis/redis.conf &&\
  sed -i 's/^logfile/# logfile/' /etc/redis/redis.conf

Change the server task in lib/tasks/fly.rake to run

    Bundler.with_original_env do
      sh "foreman start --procfile=Procfile.fly"
    end

Add a Procfile.fly:

web: bin/rails fly:server
redis: redis-server /etc/redis/redis.conf

Finally either change the REDIS_URL secret to redis://localhost:6379/1, or better yet delete the secret entirely and add REDIS_URL as an environment variable in fly.toml.

I realize this is a lot of manual steps, but I’m working on a Rails generator that will help you with changes such as these. Meanwhile, I’ve tested the above, and it works (and will be what I use for my personal application).

3 Likes