diff options
author | Duncan Grazier <itsmeduncan@gmail.com> | 2016-12-20 09:32:45 -0500 |
---|---|---|
committer | Duncan Grazier <itsmeduncan@gmail.com> | 2017-01-06 12:49:58 -0500 |
commit | 23e3e2bc2bfcc393b9164975e97d5ddc58f8bf5c (patch) | |
tree | eef842b4830786f4c7fda008844f1bdf7269bc7e /actioncable | |
parent | 98c6e4e56ca2a8f9f987e12815f7cdf66e5f1485 (diff) | |
download | rails-23e3e2bc2bfcc393b9164975e97d5ddc58f8bf5c.tar.gz rails-23e3e2bc2bfcc393b9164975e97d5ddc58f8bf5c.tar.bz2 rails-23e3e2bc2bfcc393b9164975e97d5ddc58f8bf5c.zip |
ActionCable should not raise when a connection is already open
ActionCable was throwing a "Existing connection must be closed before
opening" exception which was being picked up as a production issue in
our error monitoring software. Since this happens pretty often on any
device that allows the browser to sleep (mobile) this error was getting
triggered often.
This change removes the exception, but keeps logging the occurrence. We
now return `false` to let the caller now that `open` failed.
Diffstat (limited to 'actioncable')
-rw-r--r-- | actioncable/app/assets/javascripts/action_cable/connection.coffee | 2 | ||||
-rw-r--r-- | actioncable/test/javascript/src/unit/consumer_test.coffee | 7 |
2 files changed, 6 insertions, 3 deletions
diff --git a/actioncable/app/assets/javascripts/action_cable/connection.coffee b/actioncable/app/assets/javascripts/action_cable/connection.coffee index 29ad676290..7fd68cad2f 100644 --- a/actioncable/app/assets/javascripts/action_cable/connection.coffee +++ b/actioncable/app/assets/javascripts/action_cable/connection.coffee @@ -23,7 +23,7 @@ class ActionCable.Connection open: => if @isActive() ActionCable.log("Attempted to open WebSocket, but existing socket is #{@getState()}") - throw new Error("Existing connection must be closed before opening") + false else ActionCable.log("Opening WebSocket, current state is #{@getState()}, subprotocols: #{protocols}") @uninstallEventHandlers() if @webSocket? diff --git a/actioncable/test/javascript/src/unit/consumer_test.coffee b/actioncable/test/javascript/src/unit/consumer_test.coffee index cf8a592255..41445274eb 100644 --- a/actioncable/test/javascript/src/unit/consumer_test.coffee +++ b/actioncable/test/javascript/src/unit/consumer_test.coffee @@ -2,8 +2,11 @@ {consumerTest} = ActionCable.TestHelpers module "ActionCable.Consumer", -> - consumerTest "#connect", connect: false, ({consumer, server, done}) -> - server.on("connection", done) + consumerTest "#connect", connect: false, ({consumer, server, assert, done}) -> + server.on "connection", -> + assert.equal consumer.connect(), false + done() + consumer.connect() consumerTest "#disconnect", ({consumer, client, done}) -> |