Skip to content

Commit

Permalink
When a client detects subscription drop, mark sessions defunct. (#21841)
Browse files Browse the repository at this point in the history
This marks defunct the session the subscripton is on, as well as any sessions
that are "more stale" than it, in the sense of not having seen anything from the
peer for at least as long.  This should increase the chance that our next
attempt to communicate with the peer will not use a stale session.
  • Loading branch information
bzbarsky-apple authored and pull[bot] committed Nov 4, 2022
1 parent b5e475a commit 9a7bf8c
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/app/ReadClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -828,6 +828,29 @@ void ReadClient::OnLivenessTimeoutCallback(System::Layer * apSystemLayer, void *
"Subscription Liveness timeout with SubscriptionID = 0x%08" PRIx32 ", Peer = %02x:" ChipLogFormatX64,
_this->mSubscriptionId, _this->GetFabricIndex(), ChipLogValueX64(_this->GetPeerNodeId()));

// We didn't get a message from the server on time; it's possible that it no
// longer has a useful CASE session to us. Mark defunct all sessions that
// have not seen peer activity in at least as long as our session.
const auto & holder = _this->mReadPrepareParams.mSessionHolder;
if (holder)
{
System::Clock::Timestamp lastPeerActivity = holder->AsSecureSession()->GetLastPeerActivityTime();
_this->mpImEngine->GetExchangeManager()->GetSessionManager()->ForEachMatchingSession(
_this->mPeer, [&lastPeerActivity](auto * session) {
if (!session->IsCASESession())
{
return;
}

if (session->GetLastPeerActivityTime() > lastPeerActivity)
{
return;
}

session->MarkAsDefunct();
});
}

// TODO: add a more specific error here for liveness timeout failure to distinguish between other classes of timeouts (i.e
// response timeouts).
_this->Close(CHIP_ERROR_TIMEOUT);
Expand Down

0 comments on commit 9a7bf8c

Please sign in to comment.