From 6f5d7358422d8324be0bdf23079e1cde0c4daa99 Mon Sep 17 00:00:00 2001 From: Zang MingJie Date: Tue, 11 Jan 2022 19:55:19 +0800 Subject: [PATCH] Close exchange when session is released --- 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..f6a3c74ca117d7 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); } CHIP_ERROR ExchangeContext::StartResponseTimer()