@@ -587,7 +587,7 @@ static void prvResubscribeCommandCallback( MQTTAgentCommandContext_t * pxCommand
587
587
static MQTTStatus_t prvHandleResubscribe ( MQTTAgentContext_t * pxMqttAgentCtx ,
588
588
SubMgrCtx_t * pxCtx )
589
589
{
590
- MQTTStatus_t xStatus = MQTTSuccess ;
590
+ MQTTStatus_t xStatus ;
591
591
592
592
configASSERT ( pxCtx );
593
593
configASSERT ( pxCtx -> xMutex );
@@ -597,7 +597,7 @@ static MQTTStatus_t prvHandleResubscribe( MQTTAgentContext_t * pxMqttAgentCtx,
597
597
pxCtx -> pxCallbacks ,
598
598
& ( pxCtx -> uxSubscriptionCount ) );
599
599
600
- if ( ( xStatus == MQTTSuccess ) && ( pxCtx -> uxSubscriptionCount > 0U ) )
600
+ if ( pxCtx -> uxSubscriptionCount > 0U )
601
601
{
602
602
MQTTAgentCommandInfo_t xCommandParams =
603
603
{
@@ -1154,11 +1154,25 @@ void vMQTTAgentTask( void * pvParameters )
1154
1154
xMQTTStatus = MQTTAgent_ResumeSession ( & ( pxCtx -> xAgentContext ), xSessionPresent );
1155
1155
1156
1156
/* 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 )
1159
1158
{
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
+ }
1162
1176
}
1163
1177
}
1164
1178
else if ( xMQTTStatus == MQTTSuccess )
0 commit comments