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

when the password is incorrent,only close event, no error event #1406

Closed
liu-xinhui opened this issue Jan 27, 2022 · 13 comments
Closed

when the password is incorrent,only close event, no error event #1406

liu-xinhui opened this issue Jan 27, 2022 · 13 comments

Comments

@liu-xinhui
Copy link

const mqtt = require("mqtt");
        const client = mqtt.connect("ws://third.elevatorstar.com:7004/mqtt", {
          clientId: this.device.id,
          username: this.device.id,
          password: this.device.secret + "1",
          reconnectPeriod: 0,
        });
        client.on("connect", function() {
          console.log("connect");
        });

        client.on("close", () => {
          console.log("close");
        });

        client.on("error", function(error) {
          console.log(error);
        });

The error event no call when password is incorrent

@liu-xinhui
Copy link
Author

if i enable reconnect,only reconnect and close event.
When the error event call?

@liu-xinhui
Copy link
Author

when the password is incorrent, 4.3.4 no error event.but 4.2.1 is no this problem

this is the 4.2.1 error message,4.3.4 no this

Error: Connection refused: Bad username or password
    at MqttClient._handleConnack (client.js:1184)
    at MqttClient._handlePacket (client.js:424)
    at work (client.js:321)
    at Writable.writable._write (client.js:335)
    at doWrite (_stream_writable.js:428)
    at writeOrBuffer (_stream_writable.js:417)
    at Writable.write (_stream_writable.js:334)
    at Duplexify.ondata (_stream_readable.js:619)
    at Duplexify.emit (events.js:153)
    at addChunk (_stream_readable.js:291)

@liu-xinhui
Copy link
Author

I have try 4.3.4, 4.3.0, 4.2.8, 4.2.6,4.2.1.
only 4.2.1 has the error msg. This big problem has occured a year ago, but no one find?

@caoyawu
Copy link
Contributor

caoyawu commented Feb 4, 2022

I tested 4.3.4, it's work well and i got the error message

@liu-xinhui
Copy link
Author

@caoyawu you can try my server,ws://121.40.115.160:7024/mqtt

@caoyawu
Copy link
Contributor

caoyawu commented Feb 10, 2022

@liu-xinhui I get "Connection refused: Not authorized" for "ws://121.40.115.160:7024/mqtt"

@liu-xinhui
Copy link
Author

image

http://jsrun.net/Fj9Kp/edit

you can try online,also only close,no error

@caoyawu
Copy link
Contributor

caoyawu commented Feb 10, 2022

1644485833(1)

@liu-xinhui
Copy link
Author

@caoyawu
It should print error message every time, not sometimes print or sometimes not.
I have tried reconnect. Fortunately, you can get an error after try many times.
unfortunately, there are no error after hundreds of times

you can change https://unpkg.com/mqtt@4.3.5/dist/mqtt.min.js to https://unpkg.com/mqtt@4.2.1/dist/mqtt.min.js
will always show error msg.

@YoDaMa
Copy link
Contributor

YoDaMa commented Feb 10, 2022

@liu-xinhui can you verify that the MQTT spec defines this behavior. I'm wondering if the behavior you expected in 4.2.1 but no longer see in more recent versions was a bug.

@YoDaMa YoDaMa self-assigned this Feb 10, 2022
@Karl-Sparticle
Copy link

Karl-Sparticle commented Jun 9, 2022

It happen to me also for 4.3.7.
I have try this version https://unpkg.com/mqtt@4.2.1/dist/mqtt.min.js. There is error event if default options was used.

@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

@robertsLando
Copy link
Member

Try to reproduce the issue with MQTT v5 and feel free to reopen in case the bug persists

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

No branches or pull requests

5 participants