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

client.reconnect() will not proper set client.disconnecting to false #1284

Closed
yyjdelete opened this issue Jun 3, 2021 · 6 comments
Closed
Labels

Comments

@yyjdelete
Copy link

yyjdelete commented Jun 3, 2021

reconnect will set disconnecting and disconnected to false, but it will call end later and reset them to true, even event connect is already fired. And this make later _checkDisconnecting() always failed.

MQTT.js/lib/client.js

Lines 912 to 915 in 37b12cb

that.disconnecting = false
that.disconnected = false
that._deferredReconnect = null
that._reconnect()

this.disconnecting = true

var client  = mqtt.connect('ws://xxxx/mqtt', {'username':'test'});

    var i = 0;
client.on('connect', function() {
    console.log(client.disconnecting)
    console.log(client.disconnected)
    console.log(client.connected)
    setTimeout(() => client.reconnect(), 1000);
});
times 0
disconnecting:  false
disconnected:  undefined
connected:  true
---
times 1
disconnecting:  true
disconnected:  true
connected:  false
---
times 2
disconnecting:  false
disconnected:  false
connected:  false
  1. Another question, _setupPingTimer() is skipped when disconnected is true, so maybe I can get connection without ping for the second try? I didn't found any other code to set disconnected to false, but pingTimer maybe already broken when pingResp is already false in last connection.

    MQTT.js/lib/client.js

    Lines 1481 to 1489 in 37b12cb

    MqttClient.prototype._onConnect = function (packet) {
    if (this.disconnected) {
    this.emit('connect', packet)
    return
    }
    var that = this
    this._setupPingTimer()
@rodrigobrochado
Copy link

The disconnected property should be already deprecated, following issue #690, but seems to be abandoned.

BTW, I'm having some instabilities with the client, but I'm testing some boosts on the broker settings to see if it fixes them. While trying to find some solution, I've also take a look on the code and this part took my attention:

MQTT.js/lib/client.js

Lines 1551 to 1555 in d8be59e

MqttClient.prototype._onConnect = function (packet) {
if (this.disconnected) {
this.emit('connect', packet)
return
}

If disconnected is deprecated, the condition there should be changed to !this.connected and I doubt the goal of the return statement, although I didn't reviewed it exhaustively.
Don't know if it helps you @yyjdelete , but just to say that I'm also having issues and have some doubts in client.js

It'll be great if you have some time to comment @mcollina :)

@YoDaMa
Copy link
Contributor

YoDaMa commented Sep 28, 2021

@rodrigobrochado I'm working to aggregate all this good feedback so we can make sure it gets addressed in the "vNext" (major version update) of this library. Could you provide a discussion commend here: #1324, with a summary of what you want done from this issue. It would be helpful.

@YoDaMa YoDaMa self-assigned this Sep 28, 2021
@rodrigobrochado
Copy link

Thanks @YoDaMa. I think the huge work you've done in #1318, #1325 and are doing on vNext will probably fix this issue.

My client was misbehaving and seemed to be related to the broker rejecting packages when it was full. When digging on the client source code, I've come to the strange behavior of the disconnected property, but that was vanished on #1318.
Thanks for your work!

@robertsLando
Copy link
Member

MQTT 5.0.0 BETA is now available! Try it out and give us feedback: npm i mqtt@beta. It may fix your issues

Copy link

This is an automated message to let you know that this issue has
gone 365 days without any activity. In order to ensure that we work
on issues that still matter, this issue will be closed in 14 days.

If this issue is still important, you can simply comment with a
"bump" to keep it open.

Thank you for your contribution.

@github-actions github-actions bot added the stale label Jul 21, 2024
Copy link

github-actions bot commented Aug 4, 2024

This issue was automatically closed due to inactivity.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Aug 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants