From f332c1f6f7c1d2d128734fd42531fd69caea12c0 Mon Sep 17 00:00:00 2001 From: Damian Krolik Date: Fri, 29 Oct 2021 19:28:01 +0200 Subject: [PATCH] [app] Forget exchange context when SubscribeResponse is received SubscribeResponse is the last action in the Subscribe transaction and ExchangeContext::HandleMessage automatically closes exchanges that have no pending requests nor responses. ReadClient still kept the pointer to the exchange after receiving SubscribeResponse, so it would attempt to abort already closed exchange if the subscription was cancelled after receiving the SubscribeResponse and before receving a subsequent Report message. --- src/app/ReadClient.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/app/ReadClient.cpp b/src/app/ReadClient.cpp index 0e7ab15fe6e33a..1f908de8477a07 100644 --- a/src/app/ReadClient.cpp +++ b/src/app/ReadClient.cpp @@ -300,6 +300,10 @@ CHIP_ERROR ReadClient::OnMessageReceived(Messaging::ExchangeContext * apExchange { VerifyOrExit(apExchangeContext == mpExchangeCtx, err = CHIP_ERROR_INCORRECT_STATE); err = ProcessSubscribeResponse(std::move(aPayload)); + // Forget the context as SUBSCRIBE RESPONSE is the last message in SUBSCRIBE transaction and + // ExchangeContext::HandleMessage automatically closes a context if no other messages need to + // be sent or received. + mpExchangeCtx = nullptr; SuccessOrExit(err); } else