Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mark session for eviction on TCP Client side when disconnecting with peer. #34451

Merged
merged 1 commit into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 30 additions & 21 deletions src/transport/SessionManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -714,27 +714,7 @@ void SessionManager::HandleConnectionClosed(Transport::ActiveTCPConnectionState
{
VerifyOrReturn(conn != nullptr);

// Mark the corresponding secure sessions as defunct
mSecureSessions.ForEachSession([&](auto session) {
if (session->IsActiveSession() && session->GetTCPConnection() == conn)
{
SessionHandle handle(*session);
// Notify the SessionConnection delegate of the connection
// closure.
if (mConnDelegate != nullptr)
{
mConnDelegate->OnTCPConnectionClosed(handle, conErr);
}

// Dis-associate the connection from session by setting it to a
// nullptr.
session->SetTCPConnection(nullptr);
// Mark session as defunct
session->MarkAsDefunct();
}

return Loop::Continue;
});
MarkSecureSessionOverTCPForEviction(conn, conErr);

// TODO: A mechanism to mark an unauthenticated session as unusable when
// the underlying connection is broken. Issue #32323
Expand Down Expand Up @@ -785,6 +765,8 @@ void SessionManager::TCPDisconnect(Transport::ActiveTCPConnectionState * conn, b
conn->mPeerAddr.ToString(peerAddrBuf);
ChipLogProgress(Inet, "Disconnecting TCP connection from peer at %s.", peerAddrBuf);
mTransportMgr->TCPDisconnect(conn, shouldAbort);

MarkSecureSessionOverTCPForEviction(conn, CHIP_NO_ERROR);
}
}
#endif // INET_CONFIG_ENABLE_TCP_ENDPOINT
Expand Down Expand Up @@ -1336,6 +1318,33 @@ Optional<SessionHandle> SessionManager::FindSecureSessionForNode(ScopedNodeId pe
return mrpSession != nullptr ? MakeOptional<SessionHandle>(*mrpSession) : Optional<SessionHandle>::Missing();
}

#if INET_CONFIG_ENABLE_TCP_ENDPOINT
void SessionManager::MarkSecureSessionOverTCPForEviction(Transport::ActiveTCPConnectionState * conn, CHIP_ERROR conErr)
{
// Mark the corresponding secure sessions for eviction
mSecureSessions.ForEachSession([&](auto session) {
if (session->IsActiveSession() && session->GetTCPConnection() == conn)
{
SessionHandle handle(*session);
// Notify the SessionConnection delegate of the connection
// closure.
if (mConnDelegate != nullptr)
{
mConnDelegate->OnTCPConnectionClosed(handle, conErr);
}

// Dis-associate the connection from session by setting it to a
// nullptr.
session->SetTCPConnection(nullptr);
// Mark session for eviction.
session->MarkForEviction();
}

return Loop::Continue;
});
}
#endif // INET_CONFIG_ENABLE_TCP_ENDPOINT

/**
* Provides a means to get diagnostic information such as number of sessions.
*/
Expand Down
4 changes: 4 additions & 0 deletions src/transport/SessionManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,10 @@ class DLL_EXPORT SessionManager : public TransportMgrDelegate, public FabricTabl

void OnReceiveError(CHIP_ERROR error, const Transport::PeerAddress & source);

#if INET_CONFIG_ENABLE_TCP_ENDPOINT
void MarkSecureSessionOverTCPForEviction(Transport::ActiveTCPConnectionState * conn, CHIP_ERROR conErr);
#endif // INET_CONFIG_ENABLE_TCP_ENDPOINT

static bool IsControlMessage(PayloadHeader & payloadHeader)
{
return payloadHeader.HasMessageType(Protocols::SecureChannel::MsgType::MsgCounterSyncReq) ||
Expand Down
Loading