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

Commit

Permalink
Merge pull request #79 from mcollina/fix-79
Browse files Browse the repository at this point in the history
Don't emit clientDisconnected event when force close client.
  • Loading branch information
mcollina committed Dec 15, 2013
2 parents 4f13416 + 6904873 commit dfd58ba
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
6 changes: 2 additions & 4 deletions lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,8 @@ Client.prototype.handleAuthorizePublish = function(err, success, packet) {
Client.prototype.onNonDisconnectClose = function() {
var that = this, logger = that.logger;

that._streamClosedRequiresCleanup = true;

if (that.will) {
logger.info({ willTopic: that.will.topic }, "delivering last will");
that.server.ascoltatore.publish(
Expand Down Expand Up @@ -512,10 +514,6 @@ 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() {
Expand Down
17 changes: 17 additions & 0 deletions test/abstract_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,23 @@ module.exports = function(moscaSettings, createConnection) {
client.connect(buildOpts());
});

it("should emit an event when a client is disconnected without a disconnect", function(done) {
var client = createConnection(settings.port, settings.host);

instance.once('clientDisconnected', function(serverClient) {
expect(serverClient).not.to.be.equal(undefined);
done();
});

client.on('error', done);

client.on('connack', function() {
client.stream.end();
});

client.connect(buildOpts());
});

it("should emit a ready and closed events", function(done) {
var server = new mosca.Server(moscaSettings());
async.series([
Expand Down

0 comments on commit dfd58ba

Please sign in to comment.