Skip to content

Commit d00576b

Browse files
authoredDec 5, 2023
Merge pull request #91 from AniruddhaKanhere/main
Handled persistent session mutex relinquish correctly
2 parents 9b9e9dd + 46214d8 commit d00576b

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed
 

Diff for: ‎Common/app/mqtt/mqtt_agent_task.c

+20-6
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,7 @@ static void prvResubscribeCommandCallback( MQTTAgentCommandContext_t * pxCommand
587587
static MQTTStatus_t prvHandleResubscribe( MQTTAgentContext_t * pxMqttAgentCtx,
588588
SubMgrCtx_t * pxCtx )
589589
{
590-
MQTTStatus_t xStatus = MQTTSuccess;
590+
MQTTStatus_t xStatus;
591591

592592
configASSERT( pxCtx );
593593
configASSERT( pxCtx->xMutex );
@@ -597,7 +597,7 @@ static MQTTStatus_t prvHandleResubscribe( MQTTAgentContext_t * pxMqttAgentCtx,
597597
pxCtx->pxCallbacks,
598598
&( pxCtx->uxSubscriptionCount ) );
599599

600-
if( ( xStatus == MQTTSuccess ) && ( pxCtx->uxSubscriptionCount > 0U ) )
600+
if( pxCtx->uxSubscriptionCount > 0U )
601601
{
602602
MQTTAgentCommandInfo_t xCommandParams =
603603
{
@@ -1154,11 +1154,25 @@ void vMQTTAgentTask( void * pvParameters )
11541154
xMQTTStatus = MQTTAgent_ResumeSession( &( pxCtx->xAgentContext ), xSessionPresent );
11551155

11561156
/* Re-subscribe to all the previously subscribed topics if there is no existing session. */
1157-
if( ( xMQTTStatus == MQTTSuccess ) &&
1158-
( xSessionPresent == false ) )
1157+
if( xMQTTStatus == MQTTSuccess )
11591158
{
1160-
xMQTTStatus = prvHandleResubscribe( &( pxCtx->xAgentContext ),
1161-
&( pxCtx->xSubMgrCtx ) );
1159+
if( xSessionPresent == false )
1160+
{
1161+
xMQTTStatus = prvHandleResubscribe( &( pxCtx->xAgentContext ),
1162+
&( pxCtx->xSubMgrCtx ) );
1163+
}
1164+
else
1165+
{
1166+
/* No need to resubscribe as a session is present and the broker is aware of
1167+
* the previous subscriptions. */
1168+
if( MUTEX_IS_OWNED( pxCtx->xSubMgrCtx.xMutex ) )
1169+
{
1170+
/* Give the mutex as there is no subscribe command pending. */
1171+
( void ) xUnlockSubCtx( &( pxCtx->xSubMgrCtx ) );
1172+
}
1173+
1174+
LogInfo( "Session already present (no re-subscription)." );
1175+
}
11621176
}
11631177
}
11641178
else if( xMQTTStatus == MQTTSuccess )

0 commit comments

Comments
 (0)
Please sign in to comment.