Fix timeout check ordering in sendMessageVector#356
Open
benjacam wants to merge 2 commits intoFreeRTOS:mainfrom
Open
Fix timeout check ordering in sendMessageVector#356benjacam wants to merge 2 commits intoFreeRTOS:mainfrom
benjacam wants to merge 2 commits intoFreeRTOS:mainfrom
Conversation
Member
|
Hello @benjacam, thank you for taking the time to report this issue. You explanation and the change makes sense to me. Let us run the workflows and see if they catch any issues. |
AniruddhaKanhere
requested changes
Feb 19, 2026
Member
AniruddhaKanhere
left a comment
There was a problem hiding this comment.
There is a minor update which I would like to propose. Can you please take a look @benjacam?
Co-authored-by: Aniruddha Kanhere <kanherea@amazon.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix timeout check ordering in sendMessageVector
Description
I am running your library with MQTT_SEND_TIMEOUT_MS=0. My intention is to not block at all when attempting a send.
The library is running in a RTOS thread, and the getTimeFunction is returning the RTOS tick timer value (which is updated in another thread). In this scenario, the writev transport function successfully completed the requested send. But during the send, the other thread incremented the timer once. This means, that when this line executes:
if( calculateElapsedTime( pContext->getTime(), startTime ) > MQTT_SEND_TIMEOUT_MS )the code considers the timeout elapsed, and breaks from the while loop, before advancing pIoVectIterator and decrementing vectorsToBeSent. This means that the packet was sent, but it isn't cleared from the pending vectors.
The fix is to move the calculateElapsedTime to the very end of the while loop, after the vect state is advanced.
Test Steps
Set MQTT_SEND_TIMEOUT_MS 0. Observe logs: "sendMessageVector: Unable to send packet: Timed out." , but also add to this log the values of bytesSentOrError and bytesToSend. Eventually, you will see a log where the timeout is reported, but bytesSentOrError ==bytesToSend. Or add assertion in the body of the if( calculateElapsedTime.
Checklist:
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.