Permalink
Browse files

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.
  • Loading branch information...
essen committed Jul 11, 2012
1 parent a13fd36 commit 8ab7895ce50ec1a66442562d86945fd6000545fd
Showing with 10 additions and 0 deletions.
  1. +10 −0 priv/bullet.js
View
@@ -169,13 +169,15 @@
}
var stream = new function(){
+ var isClosed = true;
var readyState = CLOSED;
var heartbeat;
var delay = delayDefault = 80;
var delayMax = 10000;
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);

0 comments on commit 8ab7895

Please sign in to comment.