Skip to content

Commit

Permalink
Fix messageId allocate twice on deliver.
Browse files Browse the repository at this point in the history
When resubscribe options is true, then the previous subscriptions are
automatically re-subscribed.

During that process, deliver() is called.
In deliver(), send the packet is the queue.

Queued packet could be publish, pubrel, subscribe, or unsubscribe.
If the packet is publish or pubrel, its messageId should be registered
to messageIdProvider because messageIdProvider doesn't know it.

If the packet is subscribe, the messageId has already been allocated
from messageIdProvider during re-subscribing process.
So messageIdProvider knows the messageId.

deliver() didn't check the packet command so even if the packet command
is subscribe, so it tried to register the already allocated messageId.

This PR checks the packet command before registering messageId.
  • Loading branch information
redboltz committed Oct 6, 2021
1 parent 11f6321 commit 1a9518f
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -341,11 +341,13 @@ function MqttClient (streamBuilder, options) {
packet = entry.packet
debug('deliver :: call _sendPacket for %o', packet)
var send = true
if (packet.messageId && packet.messageId !== 0) {
if (!that.messageIdProvider.register(packet.messageId)) {
packet.messageId = that.messageIdProvider.allocate()
if (packet.messageId === null) {
send = false
if (packet.cmd === 'publish' || packet.cmd === 'pubrel') {
if (packet.messageId && packet.messageId !== 0) {
if (!that.messageIdProvider.register(packet.messageId)) {
packet.messageId = that.messageIdProvider.allocate()
if (packet.messageId === null) {
send = false
}
}
}
}
Expand Down

0 comments on commit 1a9518f

Please sign in to comment.