If the connection IP is wrong no event error is emitted, The client will try to reconnect forever.
I've looked inside the client code and there's no way to circumvent the problem (without changing it).
Same issue for me even the mqtt server is offline...
Hey there, I see this issue also. It happens whenever any part of the connection config is wrong (port, hostname, protocol, etc). It's not a huge issue but I'm thinking of cases where maybe an application is deployed with an incorrect config and maybe I would want to produce some logs or exit the process in when this occurs.
@mcollina do you think it is a good idea for the client to be able to detect this case and emit an event? Or do you think it makes more sense to solve it at an application level?
For anyone experiencing this issue - you could implement some basic workaround like this.
const TIMEOUT = 10
setTimeout(() => {
if (!client.connected) {
console.log(`client not connected after ${TIMEOUT} seconds`)
// process.exit(1) if you wish
}
}, TIMEOUT * 1000)
^^ You could even wrap this up in a function that returns a promise which would allow you to await to see if the connection was successful. But I'm not sure if this is a good thing to do.
^^ Original comment said it's a huge issue. I meant to type it's not a huge issue 馃槃
Most helpful comment
Same issue for me even the mqtt server is offline...