From 9d01c96f16a41b8dbde3dedf4b6762398917570f Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Mon, 10 Apr 2023 19:18:06 -0400 Subject: [PATCH] Stop trying to remove persisted subscriptions when we can't have any. 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 {