@@ -1195,9 +1195,10 @@ MqttClient.prototype._cleanUp = function (forced, done) {
1195
1195
* @param {Object } packet - packet options
1196
1196
* @param {Function } cb - callback when the packet is sent
1197
1197
* @param {Function } cbStorePut - called when message is put into outgoingStore
1198
+ * @param {Boolean } noStore - send without put to the store
1198
1199
* @api private
1199
1200
*/
1200
- MqttClient . prototype . _sendPacket = function ( packet , cb , cbStorePut ) {
1201
+ MqttClient . prototype . _sendPacket = function ( packet , cb , cbStorePut , noStore ) {
1201
1202
debug ( '_sendPacket :: (%s) :: start' , this . options . clientId )
1202
1203
cbStorePut = cbStorePut || nop
1203
1204
cb = cb || nop
@@ -1224,6 +1225,16 @@ MqttClient.prototype._sendPacket = function (packet, cb, cbStorePut) {
1224
1225
// When sending a packet, reschedule the ping timer
1225
1226
this . _shiftPingInterval ( )
1226
1227
1228
+ // If "noStore" is true, the message is sent without being recorded in the store.
1229
+ // Messages that have not received puback or pubcomp remain in the store after disconnection
1230
+ // and are resent from the store upon reconnection.
1231
+ // For resend upon reconnection, "noStore" is set to true. This is because the message is already stored in the store.
1232
+ // This is to avoid interrupting other processes while recording to the store.
1233
+ if ( noStore ) {
1234
+ sendPacket ( this , packet , cb )
1235
+ return
1236
+ }
1237
+
1227
1238
switch ( packet . cmd ) {
1228
1239
case 'publish' :
1229
1240
break
@@ -1840,7 +1851,7 @@ MqttClient.prototype._onConnect = function (packet) {
1840
1851
}
1841
1852
that . _packetIdsDuringStoreProcessing [ packet . messageId ] = true
1842
1853
if ( that . messageIdProvider . register ( packet . messageId ) ) {
1843
- that . _sendPacket ( packet )
1854
+ that . _sendPacket ( packet , undefined , undefined , true )
1844
1855
} else {
1845
1856
debug ( 'messageId: %d has already used.' , packet . messageId )
1846
1857
}
0 commit comments