Skip to content

Commit 1547195

Browse files
committed
Merge pull request #17 from Tarangp/master
Fix infinite loop when calling close when auto_reconnect is enabled
2 parents dbd2e68 + 9f3e421 commit 1547195

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

lib/ddp-client.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ DDPClient.prototype._prepareHandlers = function() {
5858

5959
self.socket.on('close', function(code, message) {
6060
self.emit('socket-close', code, message);
61-
if (self.auto_reconnect && ! self._connectionFailed) {
61+
if (self.auto_reconnect && ! self._connectionFailed && ! self._isClosing) {
6262
setTimeout(function() { self.connect(); }, self.auto_reconnect_timer);
6363
}
6464
});
@@ -197,6 +197,7 @@ DDPClient.prototype._nextId = function() {
197197
DDPClient.prototype.connect = function(connected) {
198198
var self = this;
199199
self._connectionFailed = false;
200+
self._isClosing = false;
200201

201202
if (connected) {
202203
self.addListener("connected", connected);
@@ -214,7 +215,7 @@ DDPClient.prototype.connect = function(connected) {
214215

215216
DDPClient.prototype.close = function() {
216217
var self = this;
217-
218+
self._isClosing = true;
218219
self.socket.close();
219220
};
220221

0 commit comments

Comments
 (0)