From e3f8af484223781c941d3667381ce4611653e136 Mon Sep 17 00:00:00 2001 From: Zang MingJie Date: Wed, 12 Jan 2022 05:44:03 +0800 Subject: [PATCH] Close exchange when session is released (#13448) * Close exchange when session is released * Add clearRetransTable parameter to DoClose call Co-authored-by: Andrei Litvin --- src/messaging/ExchangeContext.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/messaging/ExchangeContext.cpp b/src/messaging/ExchangeContext.cpp index 3a5cfb477ee7c7..8ec3b67989aff8 100644 --- a/src/messaging/ExchangeContext.cpp +++ b/src/messaging/ExchangeContext.cpp @@ -317,17 +317,18 @@ bool ExchangeContext::MatchExchange(const SessionHandle & session, const PacketH void ExchangeContext::OnSessionReleased() { - if (!IsResponseExpected()) + ExchangeHandle ref(*this); + + if (IsResponseExpected()) { - // Nothing to do in this case - return; + // If we're waiting on a response, we now know it's never going to show up + // and we should notify our delegate accordingly. + CancelResponseTimer(); + SetResponseExpected(false); + NotifyResponseTimeout(); } - // If we're waiting on a response, we now know it's never going to show up - // and we should notify our delegate accordingly. - CancelResponseTimer(); - SetResponseExpected(false); - NotifyResponseTimeout(); + DoClose(true /* clearRetransTable */); } CHIP_ERROR ExchangeContext::StartResponseTimer()