Skip to content

Commit 92f9f0b

Browse files
authored
[Darwin] MTRDevice _deviceMayBeReachable should mark inactive sessions as defunct (#37547)
1 parent f1e19ee commit 92f9f0b

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

src/darwin/Framework/CHIP/MTRDevice_Concrete.mm

+20-1
Original file line numberDiff line numberDiff line change
@@ -4786,9 +4786,28 @@ - (void)_deviceMayBeReachable
47864786
[self _resetSubscription];
47874787
}
47884788

4789+
auto peerScopeId = commissioner->GetPeerScopedId(self->_nodeID.unsignedLongLongValue);
47894790
auto caseSessionMgr = commissioner->CASESessionMgr();
47904791
VerifyOrDie(caseSessionMgr != nullptr);
4791-
caseSessionMgr->ReleaseSession(commissioner->GetPeerScopedId(self->_nodeID.unsignedLongLongValue));
4792+
caseSessionMgr->ReleaseSession(peerScopeId);
4793+
4794+
// TODO: make this configurable - for now use 1.5 second
4795+
#define MTRDEVICE_ACTIVE_SESSION_THRESHOLD_MILLISECONDS (15000)
4796+
auto sessionMgr = commissioner->SessionMgr();
4797+
VerifyOrDie(sessionMgr != nullptr);
4798+
sessionMgr->ForEachMatchingSession(peerScopeId, [](auto * session) {
4799+
auto secureSession = session->AsSecureSession();
4800+
if (!secureSession) {
4801+
return;
4802+
}
4803+
4804+
auto threshold = System::Clock::Timeout(MTRDEVICE_ACTIVE_SESSION_THRESHOLD_MILLISECONDS);
4805+
if ((System::SystemClock().GetMonotonicTimestamp() - session->GetLastPeerActivityTime()) < threshold) {
4806+
return;
4807+
}
4808+
4809+
session->MarkAsDefunct();
4810+
});
47924811

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

0 commit comments

Comments
 (0)