From db4382ecad20b02afdcbf33bbb8e1183b3c836f9 Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Tue, 11 Apr 2023 10:26:08 -0400 Subject: [PATCH] Stop trying to remove persisted subscriptions when we can't have any. (#26039) Specifically, for non-subscription ReadHandlers and for cases when we fail to even set up a subscription id. --- src/app/ReadHandler.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/app/ReadHandler.cpp b/src/app/ReadHandler.cpp index b393edad4fc01e..43f0fbead77fc4 100644 --- a/src/app/ReadHandler.cpp +++ b/src/app/ReadHandler.cpp @@ -142,7 +142,7 @@ ReadHandler::~ReadHandler() void ReadHandler::Close(CloseOptions options) { #if CHIP_CONFIG_PERSIST_SUBSCRIPTIONS - if (options == CloseOptions::kDropPersistedSubscription) + if (IsType(InteractionType::Subscribe) && options == CloseOptions::kDropPersistedSubscription) { auto * subscriptionResumptionStorage = InteractionModelEngine::GetInstance()->GetSubscriptionResumptionStorage(); if (subscriptionResumptionStorage) @@ -177,7 +177,12 @@ void ReadHandler::OnInitialRequest(System::PacketBufferHandle && aPayload) status = StatusIB(err).mStatus; } StatusResponse::Send(status, mExchangeCtx.Get(), /* aExpectResponse = */ false); - Close(); + // At this point we can't have a persisted subscription, since that + // happens only when ProcessSubscribeRequest returns success. And our + // subscription id is almost certianly not actually useful at this + // point, either. So don't try to mess with persisted subscriptions in + // Close(). + Close(CloseOptions::kKeepPersistedSubscription); } else {