From 8ab7895ce50ec1a66442562d86945fd6000545fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Wed, 11 Jul 2012 18:17:36 +0200 Subject: Ensure we only handle the onclose event once Fixes an issue when trying to establish the connection with Firefox 13 fails during the handshake. It would call onclose twice. --- priv/bullet.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/priv/bullet.js b/priv/bullet.js index 3a378f6..4ba2cb8 100644 --- a/priv/bullet.js +++ b/priv/bullet.js @@ -169,6 +169,7 @@ } var stream = new function(){ + var isClosed = true; var readyState = CLOSED; var heartbeat; var delay = delayDefault = 80; @@ -176,6 +177,7 @@ var transport; function init(){ + isClosed = false; readyState = CONNECTING; transport = next(); @@ -202,6 +204,12 @@ } }; transport.onclose = function(){ + // Firefox 13.0.1 sends 2 close events. + // Return directly if we already handled it. + if (isClosed){ + return; + } + clearInterval(heartbeat); if (readyState == CLOSING){ @@ -218,6 +226,8 @@ delay = delayMax; } + isClosed = true; + setTimeout(function(){ init(); }, delay); -- cgit v1.2.3