rails icon indicating copy to clipboard operation
rails copied to clipboard

Restart Action Cable server on Redis connection failures

Open MrChrisW opened this issue 1 year ago β€’ 2 comments

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

MrChrisW avatar Jun 28 '22 04:06 MrChrisW

Thanks for adding the changelog and tests!

engwan avatar Jun 28 '22 05:06 engwan

Thanks so much for taking this to the finish line @engwan. I'll review this before the week ends and we'll merge πŸ™.

jorgemanrubia avatar Jun 29 '22 08:06 jorgemanrubia

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!

brunoprietog avatar Oct 26 '22 18:10 brunoprietog

I'd like to re-raise @brunoprietog's question since there was no response for over 2 weeks.

miharekar avatar Nov 10 '22 10:11 miharekar

@brunoprietog @miharekar Please see @palkan's direction: https://github.com/rails/rails/pull/45478#discussion_r960107957 πŸ™πŸΌ

jeremy avatar Nov 10 '22 21:11 jeremy

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.

bradgessler avatar Nov 15 '22 21:11 bradgessler

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

brunoprietog avatar Nov 16 '22 01:11 brunoprietog

@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.

brunoprietog avatar Nov 16 '22 01:11 brunoprietog

Disconnecting everyone is still better than the current scenario where the process just crashes.

engwan avatar Nov 16 '22 01:11 engwan

@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 😬

bradgessler avatar Nov 16 '22 03:11 bradgessler

This has already been done in #46562, thanks @palkan! I guess this can be closed

brunoprietog avatar Nov 26 '22 19:11 brunoprietog