rails
rails copied to clipboard
Restart Action Cable server on Redis connection failures
Summary
Adapted from https://github.com/rails/rails/pull/44626 this restarts the Action Cable server on Redis connection failures, adding tests and a changelog entry.
Closes https://github.com/rails/rails/issues/27659
@treacher @engwan @jorgemanrubia
Thanks for adding the changelog and tests!
Thanks so much for taking this to the finish line @engwan. I'll review this before the week ends and we'll merge π.
Hi! Is there any news about this? I'm interested because I'm trying to use Upstash Redis, which closes connections after a while, and therefore causes ActionCable to stop. Thanks!
I'd like to re-raise @brunoprietog's question since there was no response for over 2 weeks.
@brunoprietog @miharekar Please see @palkan's direction: https://github.com/rails/rails/pull/45478#discussion_r960107957 ππΌ
I released the actioncable_redis-reconnect gem that monkey patches ActionCable as a work-around for folks who are running into this problem. For immediate relief from this issue, you can run this from the root of your Rails project:
$ bundle add actioncable_redis-reconnect
I'm going to manage the patch via this gemspec:
spec.add_dependency "actioncable", ">= 7.0", "<= 7.0.4"
When a new version of Rails is released (and Action Cable), I'll bump the dependency if this issue remains. When the permanent fix is finally released, I'll cut a final version of this gem that removes the patch, eliminates the dependency, and prints a warning that people can remove the gem.
Sorry I can't contribute yet, I still don't quite understand how Action Cable works under the hood, that's why I was asking, otherwise I would have already tried something
@bradgessler this patch restarts the Action Cable server. From what I understood from @palkan 's comment, this causes all clients to disconnect, I guess it could be problematic if there are many clients reconnecting at the same time.
Disconnecting everyone is still better than the current scenario where the process just crashes.
@bradgessler this patch restarts the Action Cable server. From what I understood from @palkan 's comment, this causes all clients to disconnect, I guess it could be problematic if there are many clients reconnecting at the same time.
Yep, it's like the early days of Rails where we'd just "restart the server" π€£βIt def "sub-optimal"
Sorry I can't contribute yet, I still don't quite understand how Action Cable works under the hood, that's why I was asking, otherwise I would have already tried something
Same boat, which is why I took the sledge hammer approach.
Disconnecting everyone is still better than the current scenario where the process just crashes.
Precisely! And I'm deploying the monkey patch in a way that won't break future releases of Rails or ActionCable for people who accidentally forget to remove the patch, which I've done plenty of times myself in production environments π¬
This has already been done in #46562, thanks @palkan! I guess this can be closed