Stop sockjs from multiplying on reconnect
Have you ever noticed when developing that every time you stop and start the server, the terminal window gets an extra duplicate line for every reconnect attempt? Well, it's because (I think) "delete" in javascript just removes the indicated name from the namespace, it doesn't actually free up an object. Those zombie objects are still there and wake up (for some transports) on reconnect. Might be different in SockJS v1 or later.
This commit is contained in:
parent
d43bc2e17e
commit
91bdffab33
1 changed files with 6 additions and 1 deletions
|
|
@ -22,6 +22,7 @@ function DataUpdater(allViewModels) {
|
|||
};
|
||||
|
||||
self.reconnect = function() {
|
||||
self._socket.close();
|
||||
delete self._socket;
|
||||
self.connect();
|
||||
};
|
||||
|
|
@ -31,7 +32,11 @@ function DataUpdater(allViewModels) {
|
|||
self._autoReconnectTrial = 0;
|
||||
};
|
||||
|
||||
self._onclose = function() {
|
||||
self._onclose = function(e) {
|
||||
if (e.code == 1000) {
|
||||
// it was us calling close
|
||||
return;
|
||||
}
|
||||
if (self._autoReconnectTrial >= self._autoReconnectDialogIndex) {
|
||||
// Only consider it a real disconnect if the trial number has exceeded our threshold.
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue