diff --git a/exec/broker.js b/exec/broker.js index eae29308d7046329791ea9271155b97c1eaa5b63..b532c14ff6fd236af50c1dd4d1f595a4f9afbd14 100644 --- a/exec/broker.js +++ b/exec/broker.js @@ -927,8 +927,10 @@ MQTT.Connection.prototype.tearDown = function() { this.sock.clearOnce('write', this.tx_once); this.tx_once = null; } - sock.close(); - this.sock = null; + if (sock !== null) { + sock.close(); + this.sock = null; + } if (this.broker.connected[this.client_id] !== undefined) delete this.broker.connected[this.client_id]; if (this.will !== null) {