Issue
You're seeing the error ERR max number of clients reached
and running out of connections in your Heroku Redis instance.
Resolution
Each of the Heroku Key-Value Store plans has a limit on the number of clients that can be connected to the Heroku Key-Value Store service.
For the smallest plans, such as the mini
plan (20 clients max.) or the premium-0
plan (40 clients max.), an application can quickly reach the connection limit if it's not properly configured and it tries to open more connections than allowed.
The Heroku Key-Value Store metrics logs can help monitor the number of active connections for your instance. However, if your application is suddenly opening a high number of connections and hitting the limit, this behavior might not be reflected in the metrics if the connection spike is short enough that it isn't caught by the metric samples.
There are several things you can do to avoid hitting the limit of concurrent connected clients, such as using a connection pooler to reduce the number of connections or setting an appropriate connection timeout to close inappropriate idle connections.
You can also configure your Heroku Key-Value Store instance to automatically close idle connections after a specific timeout with the heroku redis:timeout
command.
The following blog post goes through the above recommendations on connection timeouts and connection pooling, and includes other useful tips: https://blog.heroku.com/real-world-redis-tips
With Heroku Key-Value Store 6, the max. number of clients reached errors can also present as SSL_connect SYSCALL returned=5 errno=0 state=SSLv3/TLS write client hello
, given that Heroku Key-Value Store is rejecting the connection before the SSL handshake can succeed.
WARNING: Starting November 28, 2022, free Heroku Dynos, free Heroku Postgres, and free Heroku Key-Value Store plans will no longer be available. If you have apps using any of these resources, you must upgrade to paid plans by this date to ensure your apps continue to run and retain your data. Heroku Connect and Heroku Scheduler free plans and other third-party add-ons are not affected. Eligible students can apply for platform credits through our new Heroku for GitHub Students program. See our blog and FAQ for more info.