Skip to content
This repository has been archived by the owner on Dec 11, 2018. It is now read-only.

Commit

Permalink
Ensure we only handle the onclose event once
Browse files Browse the repository at this point in the history
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 8ab7895
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions priv/bullet.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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){
Expand All @@ -218,6 +226,8 @@
delay = delayMax;
}

isClosed = true;

setTimeout(function(){
init();
}, delay);
Expand Down

0 comments on commit 8ab7895

Please sign in to comment.