Skip to content
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

Merged
merged 4 commits into from Sep 7, 2018

Conversation

ogis-fujiwara
Copy link
Contributor

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.

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.
Copy link
Member

@mcollina mcollina left a 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

this.on('connect', this._setupPingTimer)
. As we need this to be set up as soon as possible after connection, as sending all the messages in the store might take some time.

lib/client.js Outdated
// Mark connected on connect
this.on('connect', function () {
this._onConnect = function () {
Copy link
Member

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?

Copy link
Contributor Author

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()
Copy link
Member

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')?

Copy link
Contributor Author

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
Copy link

codecov bot commented Sep 4, 2018

Codecov Report

Merging #866 into master will increase coverage by 0.03%.
The diff coverage is 93.61%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
lib/client.js 97.48% <93.61%> (+0.01%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d138144...69d6356. Read the comment docs.

Called `this._setupPingTimer()` from `_onConnect()`.
Modified `on('connect')` handler for resubscribe as top level function. The function is called from `_onConnect()`.
@ogis-fujiwara
Copy link
Contributor Author

As we need this to be set up as soon as possible after connection, as sending all the messages in the store might take some time.
I will update the code as follows:

Before stored message processing, this._setupPingTimer() is called.
In addition, resubscribe is called. Because a client might have subscribed the same topic in the stored message.

@ogis-fujiwara
Copy link
Contributor Author

I've updated all mentioned above.

Travis test was passed when I pushed changes to my topic branch. See below.
https://travis-ci.org/ogis-fujiwara/MQTT.js/builds/424621763
Would you restart failed tests?

lib/client.js Outdated
this.connectEmitter = function () {
that.emit('connect', packet)
}
this._onConnect()
Copy link
Member

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.

Copy link
Contributor Author

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.

@ogis-fujiwara
Copy link
Contributor Author

I've commited it.
All Travis test against my branch was passed as below.
https://travis-ci.org/ogis-fujiwara/MQTT.js/builds/425060666

Copy link
Member

@mcollina mcollina left a 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
Copy link
Member

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.

Copy link
Contributor Author

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?

@RangerMauve
Copy link
Contributor

I could see this changing assumptions made in existing codebases. +1 to it being semver-major.

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mcollina mcollina merged commit 6e88644 into mqttjs:master Sep 7, 2018
@ogis-fujiwara
Copy link
Contributor Author

Thank you very much for merging.

redboltz pushed a commit to redboltz/MQTT.js that referenced this pull request May 19, 2019
redboltz pushed a commit to redboltz/MQTT.js that referenced this pull request May 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants