-
Notifications
You must be signed in to change notification settings - Fork 103
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
Fix keep alive checking interval #163
Conversation
cad0967
to
0cbd24c
Compare
/* Wait 0.5 seconds by default for a ping response. */ | ||
#define MQTT_PINGRESP_TIMEOUT_MS ( 500U ) | ||
/* Wait 5 seconds by default for a ping response. */ | ||
#define MQTT_PINGRESP_TIMEOUT_MS ( 5000U ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought 5 seconds was a more reasonable default for this, for slower network conditions. From just testing locally with QEMU, it takes > 1 second for a CONNACK to be received, and sometimes with device advisor, the CONNACK takes 5-10 seconds to arrive. Since this bugfix will make this macro actually be used, we might be getting more bug reports from customers if we don't update this value now too.
e95fb56
to
7d332ac
Compare
MQTT_PINGRESP_TIMEOUT_MS was buggy See FreeRTOS/coreMQTT#163
Description:
As pointed out in https://forums.freertos.org/t/keepalivetimeout-code-in-coremqtt/12957/3, when a ping request is sent from
MQTT_ProcessLoop()
, it is only checked for a response after the keep alive interval has elapsed again. Since the broker would have disconnected the client by that time anyway if the PINGREQ was not received, the response ought to be checked earlier, as dictated byMQTT_PINGRESP_TIMEOUT_MS
.Two solutions for this issue are:
handleKeepAlive
to check based onpingReqSendTimeMs
and notlastPacketTimeMs
.MQTT_Ping()
to only updatepingReqSendTimeMs
and notlastPacketTimeMs
.The latter solution would mean that sending other packets, e.g. a PUBLISH, would reset the interval before the PINGRESP is checked, while in the former it would not.
However, the latter solution results in a smaller binary when optimizing with. This PR implements the former solution, and leaves discussion for the tradeoffs for this review-O1