Skip to content

Commit de999cd

Browse files
committed
Only evict and retry on NoSpaceSessions in initiate_unsecured
1 parent 69c0254 commit de999cd

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

rs-matter/src/transport/exchange.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -880,7 +880,7 @@ impl<'a> Exchange<'a> {
880880
/// (e.g. `PBKDFParamRequest` for PASE, or `Sigma1` for CASE).
881881
///
882882
/// If there is no space for a new session, the method will attempt to evict
883-
/// a session and retry, following the same pattern as `ReservedSession::reserve()`.
883+
/// a session and retry.
884884
///
885885
/// For flows that need direct access to the session ID (e.g. to upgrade the session
886886
/// with derived keys after a successful handshake), use
@@ -890,18 +890,19 @@ impl<'a> Exchange<'a> {
890890
crypto: C,
891891
peer_addr: network::Address,
892892
) -> Result<Self, Error> {
893-
let result = matter
893+
match matter
894894
.transport_mgr
895-
.initiate_unsecured_now(matter, &crypto, peer_addr);
896-
897-
if let Ok(exchange) = result {
898-
Ok(exchange)
899-
} else {
900-
matter.transport_mgr.evict_some_session(&crypto).await?;
895+
.initiate_unsecured_now(matter, &crypto, peer_addr)
896+
{
897+
Ok(exchange) => Ok(exchange),
898+
Err(e) if e.code() == ErrorCode::NoSpaceSessions => {
899+
matter.transport_mgr.evict_some_session(&crypto).await?;
901900

902-
matter
903-
.transport_mgr
904-
.initiate_unsecured_now(matter, &crypto, peer_addr)
901+
matter
902+
.transport_mgr
903+
.initiate_unsecured_now(matter, &crypto, peer_addr)
904+
}
905+
Err(e) => Err(e),
905906
}
906907
}
907908

0 commit comments

Comments
 (0)