diff --git a/lib/client.js b/lib/client.js index 220d517..28ff071 100644 --- a/lib/client.js +++ b/lib/client.js @@ -215,7 +215,7 @@ Client.prototype.unsubscribeMapTo = function(topic) { */ Client.prototype.unsubAndClose = function(cb) { var that = this; - this.server.persistClient(this); + this._closing = true; async.parallel(Object.keys(that.subscriptions).map(that.unsubscribeMapTo.bind(that)), function() { that.close(cb); }); @@ -491,6 +491,7 @@ Client.prototype.close = function(callback) { if (this._closed) { cleanup(); } else { + this.server.persistClient(this); this.connection.stream.on("end", cleanup); this.connection.stream.end(); }