Skip to content

Commit e62582e

Browse files
authored
[Python] Only auto re-subscribe after initial subscription (project-chip#34370)
The subscription logic waits for the first successful subscription before the Read() call is being returned (the future is awaited which is only released on handleSubscriptionEstablished). If the first subscription attempt fails (e.g. because the CASE session doesn't establish) the Read() never returns, not with an error but also not with a subscription transaction. And since the Python side has no access to the SubscriptionTransaction object at this point yet, there is also no way to stop this subscription attempt. With this change, we only resubscribe if the initial subscription was successful. This changes semantics slightly, but really allows the caller to decide if it wants to continue try to establish the subscription.
1 parent f6f873b commit e62582e

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/controller/python/chip/clusters/attribute.cpp

+6-3
Original file line numberDiff line numberDiff line change
@@ -145,18 +145,20 @@ class ReadClientCallback : public ReadClient::Callback
145145

146146
void OnSubscriptionEstablished(SubscriptionId aSubscriptionId) override
147147
{
148+
// Only enable auto resubscribe if the subscription is established successfully.
149+
mAutoResubscribeNeeded = mAutoResubscribe;
148150
gOnSubscriptionEstablishedCallback(mAppContext, aSubscriptionId);
149151
}
150152

151153
CHIP_ERROR OnResubscriptionNeeded(ReadClient * apReadClient, CHIP_ERROR aTerminationCause) override
152154
{
153-
if (mAutoResubscribe)
155+
if (mAutoResubscribeNeeded)
154156
{
155157
ReturnErrorOnFailure(ReadClient::Callback::OnResubscriptionNeeded(apReadClient, aTerminationCause));
156158
}
157159
gOnResubscriptionAttemptedCallback(mAppContext, ToPyChipError(aTerminationCause),
158160
apReadClient->ComputeTimeTillNextSubscription());
159-
if (mAutoResubscribe)
161+
if (mAutoResubscribeNeeded)
160162
{
161163
return CHIP_NO_ERROR;
162164
}
@@ -242,7 +244,8 @@ class ReadClientCallback : public ReadClient::Callback
242244
PyObject * mAppContext;
243245

244246
std::unique_ptr<ReadClient> mReadClient;
245-
bool mAutoResubscribe = true;
247+
bool mAutoResubscribe = true;
248+
bool mAutoResubscribeNeeded = false;
246249
};
247250

248251
extern "C" {

0 commit comments

Comments
 (0)