rails: ActionCable: Unable to find subscription with identifier...
Rails 5.0.0.rc1 Ruby 2.3.1 MRI + Puma
I’ve only one channel ApiChannel
, the client (iOS app) connects to the back-end, receives the subscription confirmation and immediately sends a command. Sometimes the client is greeted with RuntimeError
exception:
https://github.com/rails/rails/blob/a8df1bc345bf062e98bda64ef9638f65292c4b56/actioncable/lib/action_cable/connection/subscriptions.rb#L70
I’ve added some debugging statements to the code and from time to time the subscriptions
Hash is indeed empty (the client issues subscribe
command before), sometimes identifiers
method returns empty Array for non-empty subscriptions
(but it’s just .keys
on it).
I spent a lot of time debugging this and I’m out of ideas. Am I doing anything wrong here? Any help would be appreciated!
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 20 (6 by maintainers)
Commits related to this issue
- [Fix #25381] Avoid race condition on subscription confirmation — committed to palkan/rails by palkan 8 years ago
We’re getting quite a lot of these errors again as well, on Ruby 3.2.2 and latest Rails
It looks like the problem has reappeared. I’m getting the message even though I’m on the latest version.
@maclover7 so here is the simple Rails application to demonstrate (and reproduce reliably) the issue:
https://github.com/tomekw/ac-issue
I will try to pinpoint this but it would be wonderful if you could take a look 😃
Thank you, I’ll have a look to see what I can do to make it into a script.
@tomekw oh, I see.
There is definitely a race condition problem:
stream_from
sends confirmation without waiting forsubscribe
to finish, while you’re still broadcasting messages.PR attached https://github.com/rails/rails/pull/26547.
P.S. You can try
gem "rails", github: "palkan/rails", branch: "fix/actioncable-confirmation-race-condition"
in your reproduction app. I’ve just checked it, and it works)@frozenfoxx Since this is a race condition, it’s by nature tough to solve. 😦 The first step towards fixing would be reliable reproduction steps – would you be willing to take what you’ve experienced and try and create a “script/flow” of what one would have to do to experience the issue? From there, we can try and figure out where the issue is.
Yep, seems like a race condition to me as well 😞😬