MQTT.js icon indicating copy to clipboard operation
MQTT.js copied to clipboard

when mqtt server goes offline (host shut off), and comes back online....

Open geetee24 opened this issue 3 years ago • 4 comments

when mqtt server goes offline (host shut off), and comes back online.... this library's reconnect handler does not recover and does not reconnect.

Need example showing how to accomplish this

geetee24 avatar Mar 31 '22 03:03 geetee24

Can you provide a sample of your connection code? Note: when reconnectPeriod is set to 0 reconnection is disabled. reference

doc-han avatar Apr 04 '22 11:04 doc-han

The code is exactly the same as the example that you provide

On Mon, Apr 4, 2022 at 4:37 AM Farhan Yahaya @.***> wrote:

Can you provide a sample of your connection code? Note: when reconnectPeriod is set to 0 reconnection is disabled. reference https://github.com/mqttjs/MQTT.js#client

— Reply to this email directly, view it on GitHub https://github.com/mqttjs/MQTT.js/issues/1466#issuecomment-1087447653, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABS6UTZC32KC3Q22J7TBYELVDLH73ANCNFSM5SD7DMXA . You are receiving this because you authored the thread.Message ID: @.***>

geetee24 avatar Apr 04 '22 13:04 geetee24

I think I have the same problem - if server goes away and client keeps trying to publish,

  1. client says error / connection refused
  2. error handler fires - client "ends"
  3. client disconnecting error (below) upon publish more events - no recovery when server is back online
Error: client disconnecting
    at MqttClient._checkDisconnecting (c:\...\node_modules\mqtt\lib\client.js:577:26)
    at MqttClient.publish (c:\...\node_modules\mqtt\lib\client.js:617:12)
    ...

All examples show using client.end() in the error handler.

mqttClient.on('error', function (err) {
    console.log(err);
    client.end();
  });

When I remove client.end(), the client library reconnects successfully when the server back and continues to send messages as expected. Other clients listening successfully reconnect on their own and receive messages.

I think it's related to this open issue: #1284

Also, can someone clarify why/when we would want to call end() ?

This is against the eclipse mqtt broker.

danbo avatar Oct 23 '22 22:10 danbo

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 avatar Jul 21 '23 14:07 robertsLando