diff options
author | Matthew Draper <matthew@trebex.net> | 2016-10-01 15:14:43 +0930 |
---|---|---|
committer | Matthew Draper <matthew@trebex.net> | 2016-10-01 15:18:39 +0930 |
commit | 9588a3d66d4ca6ba122d32417aa62680f441bf40 (patch) | |
tree | 633978aa86df6eaed98595d54754b89a2b5fbbb8 /actioncable/lib/action_cable/connection | |
parent | 72f97e281059bc983eef5bc8915e53249c623dff (diff) | |
parent | 3e68d8b872b48ecb45268a7e5fcb937e68f2724f (diff) | |
download | rails-9588a3d66d4ca6ba122d32417aa62680f441bf40.tar.gz rails-9588a3d66d4ca6ba122d32417aa62680f441bf40.tar.bz2 rails-9588a3d66d4ca6ba122d32417aa62680f441bf40.zip |
Merge pull request #26547 from palkan/fix/actioncable-confirmation-race-condition
Avoid race condition on subscription confirmation
Diffstat (limited to 'actioncable/lib/action_cable/connection')
-rw-r--r-- | actioncable/lib/action_cable/connection/subscriptions.rb | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/actioncable/lib/action_cable/connection/subscriptions.rb b/actioncable/lib/action_cable/connection/subscriptions.rb index 9060183249..00511aead5 100644 --- a/actioncable/lib/action_cable/connection/subscriptions.rb +++ b/actioncable/lib/action_cable/connection/subscriptions.rb @@ -26,10 +26,14 @@ module ActionCable id_key = data["identifier"] id_options = ActiveSupport::JSON.decode(id_key).with_indifferent_access + return if subscriptions.key?(id_key) + subscription_klass = id_options[:channel].safe_constantize if subscription_klass && ActionCable::Channel::Base >= subscription_klass - subscriptions[id_key] ||= subscription_klass.new(connection, id_key, id_options) + subscription = subscription_klass.new(connection, id_key, id_options) + subscriptions[id_key] = subscription + subscription.subscribe_to_channel else logger.error "Subscription class not found: #{id_options[:channel].inspect}" end |