diff --git a/lib/client.js b/lib/client.js index 2797b7add..82275cc82 100644 --- a/lib/client.js +++ b/lib/client.js @@ -1155,7 +1155,8 @@ MqttClient.prototype._cleanUp = function (forced, done) { flush(this.outgoing) } debug('_cleanUp :: (%s) :: destroying stream', this.options.clientId) - this.stream.destroy() + // 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) debug('_cleanUp :: (%s) :: call _sendPacket with disconnect packet', this.options.clientId)