Skip to content

Commit

Permalink
[Darwin] MTRDevice _deviceMayBeReachable should mark inactive session…
Browse files Browse the repository at this point in the history
…s as defunct (#37547)
  • Loading branch information
jtung-apple authored Feb 13, 2025
1 parent f1e19ee commit 92f9f0b
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/darwin/Framework/CHIP/MTRDevice_Concrete.mm
Original file line number Diff line number Diff line change
Expand Up @@ -4786,9 +4786,28 @@ - (void)_deviceMayBeReachable
[self _resetSubscription];
}

auto peerScopeId = commissioner->GetPeerScopedId(self->_nodeID.unsignedLongLongValue);
auto caseSessionMgr = commissioner->CASESessionMgr();
VerifyOrDie(caseSessionMgr != nullptr);
caseSessionMgr->ReleaseSession(commissioner->GetPeerScopedId(self->_nodeID.unsignedLongLongValue));
caseSessionMgr->ReleaseSession(peerScopeId);

// TODO: make this configurable - for now use 1.5 second
#define MTRDEVICE_ACTIVE_SESSION_THRESHOLD_MILLISECONDS (15000)
auto sessionMgr = commissioner->SessionMgr();
VerifyOrDie(sessionMgr != nullptr);
sessionMgr->ForEachMatchingSession(peerScopeId, [](auto * session) {
auto secureSession = session->AsSecureSession();
if (!secureSession) {
return;
}

auto threshold = System::Clock::Timeout(MTRDEVICE_ACTIVE_SESSION_THRESHOLD_MILLISECONDS);
if ((System::SystemClock().GetMonotonicTimestamp() - session->GetLastPeerActivityTime()) < threshold) {
return;
}

session->MarkAsDefunct();
});

std::lock_guard lock(self->_lock);
// Use _ensureSubscriptionForExistingDelegates so that the subscriptions
Expand Down

0 comments on commit 92f9f0b

Please sign in to comment.