From 8c18904602e428a38740906b446269f2effba53d Mon Sep 17 00:00:00 2001 From: Ben Campbell Date: Wed, 18 Feb 2026 17:35:43 +0000 Subject: [PATCH 1/2] Fix timeout check ordering in sendMessageVector --- source/core_mqtt.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/source/core_mqtt.c b/source/core_mqtt.c index c7460c26c..896fa2280 100644 --- a/source/core_mqtt.c +++ b/source/core_mqtt.c @@ -851,13 +851,6 @@ static int32_t sendMessageVector( MQTTContext_t * pContext, /* MISRA Empty body */ } - /* Check for timeout. */ - if( calculateElapsedTime( pContext->getTime(), startTime ) > MQTT_SEND_TIMEOUT_MS ) - { - LogError( ( "sendMessageVector: Unable to send packet: Timed out." ) ); - break; - } - /* Update the send pointer to the correct vector and offset. */ while( ( pIoVectIterator <= &( pIoVec[ ioVecCount - 1U ] ) ) && ( sendResult >= ( int32_t ) pIoVectIterator->iov_len ) ) @@ -880,6 +873,13 @@ static int32_t sendMessageVector( MQTTContext_t * pContext, { pIoVectIterator->iov_base = ( const void * ) &( ( ( const uint8_t * ) pIoVectIterator->iov_base )[ sendResult ] ); pIoVectIterator->iov_len -= ( size_t ) sendResult; + } + + /* Check for timeout. */ + if( calculateElapsedTime( pContext->getTime(), startTime ) > MQTT_SEND_TIMEOUT_MS ) + { + LogError( ( "sendMessageVector: Unable to send packet: Timed out." ) ); + break; } } From 0bc3213189caad7ac07bf1a7af04a6ae60baee93 Mon Sep 17 00:00:00 2001 From: Ben <15067578+benjacam@users.noreply.github.com> Date: Sat, 28 Feb 2026 06:35:28 +0000 Subject: [PATCH 2/2] Update source/core_mqtt.c Co-authored-by: Aniruddha Kanhere --- source/core_mqtt.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/source/core_mqtt.c b/source/core_mqtt.c index 896fa2280..38f03a537 100644 --- a/source/core_mqtt.c +++ b/source/core_mqtt.c @@ -875,8 +875,10 @@ static int32_t sendMessageVector( MQTTContext_t * pContext, pIoVectIterator->iov_len -= ( size_t ) sendResult; } - /* Check for timeout. */ - if( calculateElapsedTime( pContext->getTime(), startTime ) > MQTT_SEND_TIMEOUT_MS ) + /* Check for timeout. */ + if( ( bytesSentOrError < ( int32_t ) bytesToSend ) && + ( bytesSentOrError >= 0 ) && + ( calculateElapsedTime( pContext->getTime(), startTime ) > MQTT_SEND_TIMEOUT_MS ) ) { LogError( ( "sendMessageVector: Unable to send packet: Timed out." ) ); break;