@@ -714,27 +714,7 @@ void SessionManager::HandleConnectionClosed(Transport::ActiveTCPConnectionState
714
714
{
715
715
VerifyOrReturn (conn != nullptr );
716
716
717
- // Mark the corresponding secure sessions as defunct
718
- mSecureSessions .ForEachSession ([&](auto session) {
719
- if (session->IsActiveSession () && session->GetTCPConnection () == conn)
720
- {
721
- SessionHandle handle (*session);
722
- // Notify the SessionConnection delegate of the connection
723
- // closure.
724
- if (mConnDelegate != nullptr )
725
- {
726
- mConnDelegate ->OnTCPConnectionClosed (handle, conErr);
727
- }
728
-
729
- // Dis-associate the connection from session by setting it to a
730
- // nullptr.
731
- session->SetTCPConnection (nullptr );
732
- // Mark session as defunct
733
- session->MarkAsDefunct ();
734
- }
735
-
736
- return Loop::Continue;
737
- });
717
+ MarkSecureSessionDefunctForConnection (conn, conErr);
738
718
739
719
// TODO: A mechanism to mark an unauthenticated session as unusable when
740
720
// the underlying connection is broken. Issue #32323
@@ -785,6 +765,8 @@ void SessionManager::TCPDisconnect(Transport::ActiveTCPConnectionState * conn, b
785
765
conn->mPeerAddr .ToString (peerAddrBuf);
786
766
ChipLogProgress (Inet, " Disconnecting TCP connection from peer at %s." , peerAddrBuf);
787
767
mTransportMgr ->TCPDisconnect (conn, shouldAbort);
768
+
769
+ MarkSecureSessionDefunctForConnection (conn, CHIP_NO_ERROR);
788
770
}
789
771
}
790
772
#endif // INET_CONFIG_ENABLE_TCP_ENDPOINT
@@ -1336,6 +1318,33 @@ Optional<SessionHandle> SessionManager::FindSecureSessionForNode(ScopedNodeId pe
1336
1318
return mrpSession != nullptr ? MakeOptional<SessionHandle>(*mrpSession) : Optional<SessionHandle>::Missing ();
1337
1319
}
1338
1320
1321
+ #if INET_CONFIG_ENABLE_TCP_ENDPOINT
1322
+ void SessionManager::MarkSecureSessionDefunctForConnection (Transport::ActiveTCPConnectionState * conn, CHIP_ERROR conErr)
1323
+ {
1324
+ // Mark the corresponding secure sessions as defunct
1325
+ mSecureSessions .ForEachSession ([&](auto session) {
1326
+ if (session->IsActiveSession () && session->GetTCPConnection () == conn)
1327
+ {
1328
+ SessionHandle handle (*session);
1329
+ // Notify the SessionConnection delegate of the connection
1330
+ // closure.
1331
+ if (mConnDelegate != nullptr )
1332
+ {
1333
+ mConnDelegate ->OnTCPConnectionClosed (handle, conErr);
1334
+ }
1335
+
1336
+ // Dis-associate the connection from session by setting it to a
1337
+ // nullptr.
1338
+ session->SetTCPConnection (nullptr );
1339
+ // Mark session as defunct
1340
+ session->MarkAsDefunct ();
1341
+ }
1342
+
1343
+ return Loop::Continue;
1344
+ });
1345
+ }
1346
+ #endif // INET_CONFIG_ENABLE_TCP_ENDPOINT
1347
+
1339
1348
/* *
1340
1349
* Provides a means to get diagnostic information such as number of sessions.
1341
1350
*/
0 commit comments