-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: problem with publish callback invoked twice #1635
fix: problem with publish callback invoked twice #1635
Conversation
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## main #1635 +/- ##
==========================================
+ Coverage 85.74% 86.28% +0.53%
==========================================
Files 13 13
Lines 1249 1254 +5
==========================================
+ Hits 1071 1082 +11
+ Misses 178 172 -6
☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR @ogis-yamazaki ! Would you mind to add a unit test that covers this?
lib/client.js
Outdated
@@ -1626,6 +1626,7 @@ class MqttClient extends EventEmitter { | |||
err = new Error('Publish error: ' + errors[pubackRC]) | |||
err.code = pubackRC | |||
cb(err, packet) | |||
cb = null |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cb = null | |
// prevent invoking callback twice when deleting message from store #1511 | |
cb = null |
Added qos 1 and qos2 tests. When an error occurs in PUBREC, added a process to remove the message from the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By checking the code on my side I saw that this:
delete this.outgoing[messageId]
this.outgoingStore.del(packet, cb)
this.messageIdProvider.deallocate(messageId)
this._invokeStoreProcessingQueue()
Is used 3 times in the code. Would you mind to create a dedicated function for that?
I see we also have a method removeOutgoingMessage
, it doesn't call _invokeStoreProcessingQueue
and messageIdProvider.deallocate
maybe that's an error too?
OK
As you said, additional processing was needed. In
The There is a problem if |
Would you mind to also fix those errors or do you prefer to do that in a separeted PR? |
79a5789
to
b5ffdd8
Compare
Fixed in this PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, now everything is much cleaner. Thanks @ogis-yamazaki 🙏🏼
User callback is executed twice if the received PUBACK indicates failure (by reason code).
Related issue: #1511
The following modification prevents the callback from invoked twice.
resonCode
in PUBACK to failure, set the cb variable to NULL after the callback is invoked.