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

Fix keep alive checking interval #163

Merged
merged 6 commits into from
Jul 1, 2021

Conversation

muneebahmed10
Copy link
Contributor

@muneebahmed10 muneebahmed10 commented Jun 29, 2021

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 by MQTT_PINGRESP_TIMEOUT_MS.

Two solutions for this issue are:

  1. Update handleKeepAlive to check based on pingReqSendTimeMs and not lastPacketTimeMs.
  2. Update MQTT_Ping() to only update pingReqSendTimeMs and not lastPacketTimeMs.

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 -O1. This PR implements the former solution, and leaves discussion for the tradeoffs for this review

/* 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 )
Copy link
Contributor Author

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.

source/core_mqtt.c Outdated Show resolved Hide resolved
@muneebahmed10 muneebahmed10 merged commit 6b222a7 into FreeRTOS:main Jul 1, 2021
@muneebahmed10 muneebahmed10 deleted the fix-keep-alive branch July 1, 2021 17:13
boraozgen added a commit to Nantis-GmbH/mbed-aws-client that referenced this pull request Oct 13, 2021
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

Successfully merging this pull request may close these issues.

3 participants