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

When the network is disconnected abnormally, the disconnection event is not triggered in time

Open honyudeng opened this issue 5 years ago • 1 comments

The "offline" event will be triggered in a few seconds client.on('offline', (error) => { console.log('offline:', error) }) offline This event triggered too slowly What event can I call back in time to disconnect?

honyudeng avatar Dec 21 '19 02:12 honyudeng

I believe what you need is that keepalive value when you initialize the client.

MQTT client detects the disconnection via a packet called pingreq, it will send a pingreq packet for every keepalive duration, if it does not receive the ack message from the broker, it will consider the connection is lost. The default value of keepAlive is 60 seconds based on the documentation, it means you can only detect the disconnection after a minute or so.

If you would like to detect the disconnection sooner, just reduce the keepalive value.

lhthang96 avatar Aug 01 '22 14:08 lhthang96

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[bot] avatar Aug 02 '23 01:08 github-actions[bot]

This issue was automatically closed due to inactivity.

github-actions[bot] avatar Aug 17 '23 01:08 github-actions[bot]