@@ -175,7 +175,7 @@ function sendPacket (client, packet, cb) {
175
175
debug ( 'sendPacket :: writing to stream' )
176
176
const result = mqttPacket . writeToStream ( packet , client . stream , client . options )
177
177
debug ( 'sendPacket :: writeToStream result %s' , result )
178
- if ( ! result && cb ) {
178
+ if ( ! result && cb && cb !== nop ) {
179
179
debug ( 'sendPacket :: handle events on `drain` once through callback.' )
180
180
client . stream . once ( 'drain' , cb )
181
181
} else if ( cb ) {
@@ -190,6 +190,8 @@ function flush (queue) {
190
190
Object . keys ( queue ) . forEach ( function ( messageId ) {
191
191
if ( typeof queue [ messageId ] . cb === 'function' ) {
192
192
queue [ messageId ] . cb ( new Error ( 'Connection closed' ) )
193
+ // This is suspicious. Why do we only delete this if we have a callbck?
194
+ // If this is by-design, then adding no as callback would cause this to get deleted unintentionally.
193
195
delete queue [ messageId ]
194
196
}
195
197
} )
@@ -569,7 +571,7 @@ MqttClient.prototype._handlePacket = function (packet, done) {
569
571
570
572
MqttClient . prototype . _checkDisconnecting = function ( callback ) {
571
573
if ( this . disconnecting ) {
572
- if ( callback ) {
574
+ if ( callback && callback !== nop ) {
573
575
callback ( new Error ( 'client disconnecting' ) )
574
576
} else {
575
577
this . emit ( 'error' , new Error ( 'client disconnecting' ) )
@@ -1581,7 +1583,7 @@ MqttClient.prototype._handleAck = function (packet) {
1581
1583
const that = this
1582
1584
let err
1583
1585
1584
- if ( ! cb ) {
1586
+ if ( ! cb || cb === nop ) {
1585
1587
debug ( '_handleAck :: Server sent an ack in error. Ignoring.' )
1586
1588
// Server sent an ack in error, ignore it.
1587
1589
return
0 commit comments