-
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
Delayed emit timing of connect
event.
#866
Conversation
Emit `connect` event after processing of `outgoingStore` is completed. Problem: When client publish new message during proccessing of publish/pubrel messages in `outgoingStore`, the newly published message interrupts the process. As a result, messages are not sent by published time order. Outcomes: Above message order problem is fixed by this commit. Added unit test verifies this case.
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.
Good spot, you'd also need to change
Line 202 in 5379f1c
this.on('connect', this._setupPingTimer) |
lib/client.js
Outdated
// Mark connected on connect | ||
this.on('connect', function () { | ||
this._onConnect = function () { |
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.
can you move this to a top level function instead?
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.
Yes, I will do that.
lib/client.js
Outdated
@@ -141,6 +144,7 @@ function MqttClient (streamBuilder, options) { | |||
this.once('close', remove) | |||
outStore.on('end', function () { | |||
that.removeListener('close', remove) | |||
that.connectEmitter() |
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.
can you just emit('connect')
?
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.
connack
packet is mandatory parameter when emitting connect
.
So I introduced that.connectEmitter()
to capture connack
packet.
Instead of do that, I can store connack
packet and pass it to emit connect
.
Which one is better?
Codecov Report
@@ Coverage Diff @@
## master #866 +/- ##
==========================================
+ Coverage 94.1% 94.13% +0.03%
==========================================
Files 8 8
Lines 763 767 +4
Branches 190 190
==========================================
+ Hits 718 722 +4
Misses 45 45
Continue to review full report at Codecov.
|
Called `this._setupPingTimer()` from `_onConnect()`. Modified `on('connect')` handler for resubscribe as top level function. The function is called from `_onConnect()`.
Before stored message processing, |
I've updated all mentioned above. Travis test was passed when I pushed changes to my topic branch. See below. |
lib/client.js
Outdated
this.connectEmitter = function () { | ||
that.emit('connect', packet) | ||
} | ||
this._onConnect() |
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.
You can pass the packet to _onConnect(packet)
and wrap it in the closures there.
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, I will commit it.
I've commited it. |
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.
@mqttjs/core I think this is semver-major. What do you all think?
Are there any other semver-major changes that we might want to do? (apart from #827).
lib/client.js
Outdated
storeDeliver() | ||
}) | ||
// True if connection is first time. | ||
this.firstConnection = true |
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.
can you make this _firstConnection
? this should ideally be private.
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.
I committed this. Could you please review?
I could see this changing assumptions made in existing codebases. +1 to it being semver-major. |
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
Thank you very much for merging. |
Delayed emit timing of `connect` event.
Delayed emit timing of `connect` event.
Emit
connect
event after processing ofoutgoingStore
is completed.Problem:
When client publish new message during proccessing of publish/pubrel messages in
outgoingStore
, the newly published message interrupts the process. As a result, messages are not sent by published time order.Outcomes:
Above message order problem is fixed by this commit. Added unit test verifies this case.