-
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]: Getting Keepalive timeout when using client.handleMessage #1935
Comments
Hi @vivek-doshi-genea and thanks for your issue, would you like to submit a PR to fix this bug? Also could you try to use a QoS > 0 in publish and subscribe and see if the issue happens anyway? I have a feel the problem is that we are not shifting ping when only receiving messages and so keepalive timer triggers: MQTT.js/src/lib/handlers/index.ts Line 31 in 1ca3f9e
|
Yes @robertsLando , I would love to contribute, but I am not the expert in this, just trying to get better understanding on all of this at the moment. I was going through the other issues didn't get much understanding from that but I also felt that it might be something related to |
@vivek-doshi-genea You could try to send pingreq your own maybe? Just use |
Lot of work as been done in order to improve keepalive management. The last rework introduced a keepalive manager that works following the specs: MQTT.js/src/lib/KeepaliveManager.ts Lines 91 to 110 in 1ca3f9e
In poor words giving the keepalive you pass to the client, it creates an interval every keepalive / 2 seconds. So every two iterations of the interval it sends a pingreq, if it does 3 iterations without receiving any pingresp (or other messages, see |
I've added the
Any idea about this one ? this was happening after error, I am afraid if any other error might lead to this behaviour
|
@robertsLando True, I've tested out with both the way |
@vivek-doshi-genea the solution is not ideal as increeses traffic a lot, could I ask you why not using the |
If you switch to the |
Okay, let's take an example, of 1000 devices are generating an events, let's say 1 event per second per device , heavy sync operation are done for each messages like ,
If we do all these processes with Possible solution to resolve this might need to divert the messages to somewhere else like
And then consume the messages directly from there. |
How this Is there any document available for this? Or Is it using any Mqtt Broker feature? |
@vivek-doshi-genea The backpressure is done internally using nodejs streams. I suggest you to firstly read nodejs stream docs to understand how stream works and then check this code: Line 760 in 1ca3f9e
Firstly we build the stream based on the protocol, then we pipe that stream to a writeable stream so we can handle the |
MQTTjs Version
5
Broker
AWS IoT Core
Environment
NodeJS
Description
I've created 2 files
Publisher.js
andSubscriber.js
Publisher.js
: Publish 1 message per second on topiciot-device/events
Subscriber.js
: Subscribed to topiciot-device/events
, and get message viahandleMessage
also added 2 sec await to mock DB or Third party API call processNow when I run both the files, publisher keeps publishing the messages without any issue.
Issues
Keepalive timeout
after ~1 min of executionThe issue is not random, it appears every time.
Minimal Reproduction
Node js version : v20.17.0
NPM version : 10.8.2
mqtt npm: 5.10.1
Certificates to connect to broker
Steps :
node Publisher.js
node Subscriber.js
Keepalive timeout
and all the above points mentionedCode for both files,
Publisher.js
Subscriber.js
Debug logs
Publisher Logs :
Subscriber Logs :
The text was updated successfully, but these errors were encountered: