Skip to content

Commit

Permalink
Mark a session defunct if an attempt to send a message on it fails ou…
Browse files Browse the repository at this point in the history
…tright. (#26778)

This is most likely a "No route to host" error or something like that, which
_may_ get cleared up with a new dns-sd resolve and session re-establishment.
  • Loading branch information
bzbarsky-apple authored May 24, 2023
1 parent 7e5267b commit 80bce56
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions src/messaging/ExchangeContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ CHIP_ERROR ExchangeContext::SendMessage(Protocols::Id protocolId, uint8_t msgTyp
return CHIP_ERROR_MISSING_SECURE_SESSION;
}

SessionHandle session = GetSessionHandle();
CHIP_ERROR err;

#if CONFIG_BUILD_FOR_HOST_UNIT_TEST
Expand All @@ -213,17 +214,29 @@ CHIP_ERROR ExchangeContext::SendMessage(Protocols::Id protocolId, uint8_t msgTyp
else
{
#endif
err = mDispatch.SendMessage(GetExchangeMgr()->GetSessionManager(), mSession.Get().Value(), mExchangeId, IsInitiator(),
err = mDispatch.SendMessage(GetExchangeMgr()->GetSessionManager(), session, mExchangeId, IsInitiator(),
GetReliableMessageContext(), reliableTransmissionRequested, protocolId, msgType,
std::move(msgBuf));
#if CONFIG_BUILD_FOR_HOST_UNIT_TEST
}
#endif
// We should only cancel the response timer if the ExchangeContext fails to send the message that starts the response timer.
if (err != CHIP_NO_ERROR && startedResponseTimer)
if (err != CHIP_NO_ERROR)
{
CancelResponseTimer();
SetResponseExpected(false);
// We should only cancel the response timer if the ExchangeContext fails to send the message that starts the response
// timer.
if (startedResponseTimer)
{
CancelResponseTimer();
SetResponseExpected(false);
}

// If we can't even send a message (send failed with a non-transient
// error), mark the session as defunct, just like we would if we
// thought we sent the message and never got a response.
if (session->IsSecureSession() && session->AsSecureSession()->IsCASESession())
{
session->AsSecureSession()->MarkAsDefunct();
}
}

// Standalone acks are not application-level message sends.
Expand Down

0 comments on commit 80bce56

Please sign in to comment.