Skip to content

Commit

Permalink
ExchangeCtx: Fix issue with response timer cancellation (#26215)
Browse files Browse the repository at this point in the history
* ExchangeCtx: Fix issue with response timer cancellation

* Add a boolean to record whether the message starts the reponse timer
  • Loading branch information
wqx6 authored and pull[bot] committed Sep 1, 2023
1 parent b52536b commit 9138696
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions src/messaging/ExchangeContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ CHIP_ERROR ExchangeContext::SendMessage(Protocols::Id protocolId, uint8_t msgTyp
bool reliableTransmissionRequested =
GetSessionHandle()->RequireMRP() && !sendFlags.Has(SendMessageFlags::kNoAutoRequestAck) && !IsGroupExchangeContext();

bool startedResponseTimer = false;
// If a response message is expected...
if (sendFlags.Has(SendMessageFlags::kExpectResponse) && !IsGroupExchangeContext())
{
Expand All @@ -177,6 +178,7 @@ CHIP_ERROR ExchangeContext::SendMessage(Protocols::Id protocolId, uint8_t msgTyp
SetResponseExpected(false);
return err;
}
startedResponseTimer = true;
}
}

Expand Down Expand Up @@ -217,8 +219,8 @@ CHIP_ERROR ExchangeContext::SendMessage(Protocols::Id protocolId, uint8_t msgTyp
#if CONFIG_BUILD_FOR_HOST_UNIT_TEST
}
#endif

if (err != CHIP_NO_ERROR && IsResponseExpected())
// We should only cancel the response timer if the ExchangeContext fails to send the message that starts the response timer.
if (err != CHIP_NO_ERROR && startedResponseTimer)
{
CancelResponseTimer();
SetResponseExpected(false);
Expand Down Expand Up @@ -267,8 +269,11 @@ void ExchangeContext::DoClose(bool clearRetransTable)
mExchangeMgr->GetReliableMessageMgr()->ClearRetransTable(this);
}

// Cancel the response timer.
CancelResponseTimer();
if (IsResponseExpected())
{
// Cancel the response timer.
CancelResponseTimer();
}
}

/**
Expand Down Expand Up @@ -590,12 +595,15 @@ CHIP_ERROR ExchangeContext::HandleMessage(uint32_t messageCounter, const Payload
return CHIP_ERROR_INCORRECT_STATE;
}

// Since we got the response, cancel the response timer.
CancelResponseTimer();
if (IsResponseExpected())
{
// Since we got the response, cancel the response timer.
CancelResponseTimer();

// If the context was expecting a response to a previously sent message, this message
// is implicitly that response.
SetResponseExpected(false);
// If the context was expecting a response to a previously sent message, this message
// is implicitly that response.
SetResponseExpected(false);
}

// Don't send messages on to our delegate if our dispatch does not allow
// those messages.
Expand Down

0 comments on commit 9138696

Please sign in to comment.