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

Commit

Permalink
Modified Client.close to handle streams which have already ended.
Browse files Browse the repository at this point in the history
  • Loading branch information
ldstein committed Dec 10, 2013
1 parent 2dbfab8 commit d20bdc9
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -510,13 +510,16 @@ Client.prototype.close = function(callback) {
}
};

that.connection.stream.on('end' , function(){
that._streamClosedRequiresCleanup = true;
});

that._closing = true;

async.parallel(Object.keys(that.subscriptions).map(that.unsubscribeMapTo.bind(that)), function() {
that.server.persistClient(that);
if(that.connection.stream.destroyed){
if(callback) {
callback();
}
if(that._streamClosedRequiresCleanup){
cleanup();
} else {
that.connection.stream.on('end', cleanup);
that.connection.stream.end();
Expand Down

0 comments on commit d20bdc9

Please sign in to comment.