Skip to content

Commit

Permalink
[op-creds] Fix RemoveFabric command (#13869)
Browse files Browse the repository at this point in the history
RemoveFabric command called for the fabric that is used to
process the message crashes in SessionHolder. The reason is
that sessions for the removed fabric are expired when the
command's exchange is closed after sending the response
and that triggers closing all associated session holders.
An exchange's session holder closes the exchange which
in this case results in an attempt to close an exchange
that is in the middle of closing...
  • Loading branch information
Damian-Nordic authored and pull[bot] committed Feb 12, 2024
1 parent 5c5d87e commit 1235776
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -373,12 +373,14 @@ bool emberAfOperationalCredentialsClusterRemoveFabricCallback(app::CommandHandle
FabricIndex currentFabricIndex = commandObj->GetAccessingFabricIndex();
if (currentFabricIndex == fabricBeingRemoved)
{
// If the current fabric is being removed, expiring all the secure sessions causes crashes as
// the message sent by emberAfSendImmediateDefaultResponse() is still in the queue. Also, RMP
// retries to send the message and runs into issues.
// We are hijacking the exchange delegate here (as no more messages should be received on this exchange),
// and wait for it to close, before expiring the secure sessions for the fabric.
// If the current fabric is being removed, don't expire the secure sessions immediately as they are
// still needed to send a pending message generated by emberAfSendImmediateDefaultResponse().
// Hijack the exchange delegate here (as no more messages should be received on this exchange),
// and wait for it to close, before expiring the secure sessions for the fabric. Also, suppress MRP
// usage since the MRP engine still holds an exchange even after it's closed, and the engine references
// the associated session object.
// TODO: https://github.com/project-chip/connectedhomeip/issues/9642
ec->SetAutoRequestAck(false);
ec->SetDelegate(&gFabricCleanupExchangeDelegate);
}
else
Expand Down
7 changes: 7 additions & 0 deletions src/messaging/ExchangeContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,13 @@ bool ExchangeContext::MatchExchange(const SessionHandle & session, const PacketH

void ExchangeContext::OnSessionReleased()
{
if (mFlags.Has(Flags::kFlagClosed))
{
// Exchange is already being closed. It may occur when closing an exchange after sending
// RemoveFabric response which triggers removal of all sessions for the given fabric.
return;
}

ExchangeHandle ref(*this);

if (IsResponseExpected())
Expand Down

0 comments on commit 1235776

Please sign in to comment.