aboutsummaryrefslogtreecommitdiffstats
path: root/actioncable/app/assets/javascripts
diff options
context:
space:
mode:
authorPratik Naik <pratiknaik@gmail.com>2016-02-18 14:38:22 -0600
committerPratik Naik <pratiknaik@gmail.com>2016-02-23 09:37:49 -0600
commit725c913c902902d84a595760cd9fdb933cfa824d (patch)
treec2167f507c2a37e4874b9f15392081154d67a129 /actioncable/app/assets/javascripts
parent832f88bdf35f5ac3333f3ccc2100223e32ca034a (diff)
downloadrails-725c913c902902d84a595760cd9fdb933cfa824d.tar.gz
rails-725c913c902902d84a595760cd9fdb933cfa824d.tar.bz2
rails-725c913c902902d84a595760cd9fdb933cfa824d.zip
Treat 'closing' state as closed.
We are seeing cases where the websockets get stuck in the 'closing' state after a tab has been in background for a while. So lets treat those websockets as closed.
Diffstat (limited to 'actioncable/app/assets/javascripts')
-rw-r--r--actioncable/app/assets/javascripts/action_cable/connection.coffee9
1 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 866bb20870..b1343a111c 100644
--- a/actioncable/app/assets/javascripts/action_cable/connection.coffee
+++ b/actioncable/app/assets/javascripts/action_cable/connection.coffee
@@ -16,11 +16,11 @@ class ActionCable.Connection
false
open: =>
- if @webSocket and not @isState("closed")
+ if @webSocket and not @isClosed()
console.log("[cable] Attemped to open WebSocket, but existing socket is #{@getState()}", Date.now())
throw new Error("Existing connection must be closed before opening")
else
- console.log("[cable] Opening WebSocket", Date.now())
+ console.log("[cable] Opening WebSocket, current state is #{@getState()}", Date.now())
@webSocket = new WebSocket(@consumer.url)
@installEventHandlers()
true
@@ -30,7 +30,7 @@ class ActionCable.Connection
reopen: ->
console.log("[cable] Reopening WebSocket, current state is #{@getState()}", Date.now())
- if @isState("closed")
+ if @isClosed()
@open()
else
try
@@ -44,6 +44,9 @@ class ActionCable.Connection
# Private
+ isClosed: ->
+ @isState("closing", "closed")
+
isState: (states...) ->
@getState() in states