From 34873cacbe8051df528fc88f60debe2e53bd372a Mon Sep 17 00:00:00 2001 From: Pierre Cauchois Date: Tue, 7 Nov 2017 13:26:47 -0800 Subject: [PATCH 1/2] Add error when destroying stream to generate close event even when the network connection is down --- lib/client.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/client.js b/lib/client.js index b1f9d7056..291814cfd 100644 --- a/lib/client.js +++ b/lib/client.js @@ -692,7 +692,7 @@ MqttClient.prototype._cleanUp = function (forced, done) { } if (forced) { - this.stream.destroy() + this.stream.destroy(new Error('stream forcefully closed by the client')) } else { this._sendPacket( { cmd: 'disconnect' }, From fccb81dc82180e701da8fc2390fd0023a02608a2 Mon Sep 17 00:00:00 2001 From: Daniel Lando Date: Wed, 28 Jun 2023 08:25:33 +0200 Subject: [PATCH 2/2] fix: add comment --- lib/client.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/client.js b/lib/client.js index 086b6fd96..82275cc82 100644 --- a/lib/client.js +++ b/lib/client.js @@ -1155,6 +1155,7 @@ MqttClient.prototype._cleanUp = function (forced, done) { flush(this.outgoing) } debug('_cleanUp :: (%s) :: destroying stream', this.options.clientId) + // pass an error here to be sure the 'error' event is emitted on stream, fixes #713 this.stream.destroy(new Error('stream forcefully closed by the client')) } else { const packet = xtend({ cmd: 'disconnect' }, opts)