-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
[Bug]: Client times out every 96 seconds #1861
Comments
Got mqttjs logs too? |
I have same problem. mosquitto-bug-client.log my client code as below and i executed command import mqtt from 'mqtt'
console.log(`Env:DEBUG = ${process.env.DEBUG}`)
const client = mqtt.connect('ws://localhost:8080', {
keepalive: 30,
will: {
topic: "DAT/debugger/app",
payload: Buffer.from("0"),
qos: 0,
retain: true,
}
})
client.on('error', (err) => {
// console.error("%O", err)
})
client.on('connect', () => {
// console.log('connect')
client.subscribe('DAT/debugger/#')
})
client.on('message', (topic, payload, packet) => {
// console.log('%O:%O(%O)', topic, payload, packet)
})
client.on('close', () => {
// console.log('close')
}) |
v5.5.4 seems reschedule a pingTimer at send a control packet. I think client like a mqtt.js need send a pingreq when have not sent control packet in keepalive interval. |
In my last PR I have fixed an issue related to keepalive: #1855 Problem is that in previous implementation keepalive was shifetd on every packet sent and this is a problem as not only the pingreq packet is shifted but also the check. This means that if you have a client with a broken connection that keeps doing publish the connection is never closed as the keepalive never triggers by being always shifted... I would need to see mqttjs logs not broker logs in order to understand what's going on here |
Here is mqttjs logs. I glad if it helps. I'm sorry for giving it a confusing log file name. |
From your logs it seems that the broker is closing the stream:
What broker are you using? Could it be that your broker is not respecting specs and it expects a pingreq even if you are actually sending other control packets? |
I use 'mosquitto' provided by the official Docker image. It's tagged as '2.0.18'. |
In my understanding, the client is not sending packets until it's disconnected after send packets of subscribe. I think mqttjs should send a pingreq in this scenario. However, the PingTimer is rescheduled every time a published message is received, preventing it from sending a pingreq. |
@makoto-tsudo Thanks for your feedbacks, thanks to them I have been able to find the reason of the unwanted disconnections. The problem was that to fix the other issue related to keepalive where the ping was shifted on every message written to socket (cause the keepalive to not close the connection) now we was shifting on every message received from broker but in case of a client that only receives messages this causes the keepalive management to never send a pingreq thinking that we are already communicatig with the broker so we don't send the pingreq and the broker closes the connection after keepalive*1.5 seconds as per specs I have a WIP to do lot of improvements to the keepalive management but you need to wait for that #1865 In the meanwhile I will create a new patch release to fix the issue Fixed by #1866 |
@robertsLando Thanks for the quick response. |
MQTTjs Version
5.5.5
Broker
Mosquitto 2.0.18
Environment
NodeJS
Description
My NestJS application works fine using MQTT.js 5.5.4, but when upgrading to 5.5.5, my connection keeps timing out.
Minimal Reproduction
I'm initializing the connection like this:
There is nothing fancy I do here. The NestJS application keeps logging that it has restarted microservices every 96 seconds.
Debug logs
It's the
Client mqttjs_XXXXXXXX has exceeded timeout, disconnecting.
that signals the problem.The text was updated successfully, but these errors were encountered: