Skip to content

Commit

Permalink
When a client detects subscription drop, mark sessions defunct. (proj…
Browse files Browse the repository at this point in the history
…ect-chip#21841)

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 isiu-apple committed Sep 16, 2022
1 parent 42f8fa0 commit bd7bc70
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 bd7bc70

Please sign in to comment.