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 race condition in handleKeepAlive #258

Merged
merged 1 commit into from
Aug 24, 2023
Merged

Fix race condition in handleKeepAlive #258

merged 1 commit into from
Aug 24, 2023

Conversation

saidrhs
Copy link
Contributor

@saidrhs saidrhs commented Aug 23, 2023

Fix race condition in handleKeepAlive

Description

The code for handleKeepAlive() (which is invoked as part of MQTT_ProcessLoop()) does not invoke the STATE_UPDATE_HOOK macros, but still reads from pContext->lastPacketTxTime. Therefore, this causes a RW race condition which is picked up by ThreadAnalyzer. With a sufficiently meddlesome scheduler, the value of lastPacketTxTime could be different for each time it is checked inside of handleKeepAlive() , causing unreliable behavior in the transmission of KeepAlive packets.

Test Steps

Checklist:

  • I have tested my changes. No regression in existing tests.
  • I have modified and/or added unit-tests to cover the code changes in this Pull Request.

Related Issue

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Copy link
Member

@AniruddhaKanhere AniruddhaKanhere left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved with a Nit pick about the PR description: You have said as seen from above report but I do not see any report in the description attached to the PR.

@saidrhs saidrhs merged commit 9bfc624 into FreeRTOS:main Aug 24, 2023
@saidrhs saidrhs deleted the dev branch October 25, 2023 14:46
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