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

disconnect event did not being triggered while network being closed #1584

Open
laxian opened this issue Mar 13, 2023 · 3 comments
Open

disconnect event did not being triggered while network being closed #1584

laxian opened this issue Mar 13, 2023 · 3 comments

Comments

@laxian
Copy link

laxian commented Mar 13, 2023

As the title says

this is my test code:

const mqtt = require('mqtt')

const host = 'broker.emqx.io'
const port = '1883'
const clientId = `S1RRR2232D0003_1`

const connectUrl = `mqtt://${host}:${port}`
const topic = "test-js"

const client = mqtt.connect(connectUrl, {
    clientId,
    clean: true,
    connectTimeout: 5 * 1000,
    reconnectPeriod: 5 * 1000,
    keepalive: 10,
})

client.on('connect', function () {
    client.publish(topic, 'Heartbeat Messages', { qos: 0, retain: false }, function (error) {
        if (error) {
            console.error(error)
        }
        else {
            console.log('Heartbeat Messages Sent.')
        }
    })
})

client.on('disconnect', function (error) {
    if (error) {
        console.error(error)
    }
})

client.on('offline', function (error) {
        console.error(error)
})

image

Why disconnect and offline events not being triggered?
Thank you!

@laxian
Copy link
Author

laxian commented Mar 15, 2023

on Ubuntu or Mac
In case I start the test process on WIFI named ap1,
I won't receive offline event if I switch WIFI to ap2 or turn off WIFI, until I reconnect to ap1

For comparison, if you use Python paho-mqtt library to switch or close WIFI, you can receive on_ disconnect,
In addition, switching WIFI can correctly reconnect successfully

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.

@robertsLando
Copy link
Member

@laxian are you able to reproduce the issue with latest version?

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

2 participants