Skip to content

Commit

Permalink
[Python] Only auto re-subscribe after initial subscription
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
agners committed Jul 17, 2024
1 parent df8c9da commit a0dbc95
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/controller/python/chip/clusters/attribute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,18 +145,20 @@ class ReadClientCallback : public ReadClient::Callback

void OnSubscriptionEstablished(SubscriptionId aSubscriptionId) override
{
// Only enable auto resubscribe if the subscription is established successfully.
mAutoResubscribeNeeded = mAutoResubscribe;
gOnSubscriptionEstablishedCallback(mAppContext, aSubscriptionId);
}

CHIP_ERROR OnResubscriptionNeeded(ReadClient * apReadClient, CHIP_ERROR aTerminationCause) override
{
if (mAutoResubscribe)
if (mAutoResubscribeNeeded)
{
ReturnErrorOnFailure(ReadClient::Callback::OnResubscriptionNeeded(apReadClient, aTerminationCause));
}
gOnResubscriptionAttemptedCallback(mAppContext, ToPyChipError(aTerminationCause),
apReadClient->ComputeTimeTillNextSubscription());
if (mAutoResubscribe)
if (mAutoResubscribeNeeded)
{
return CHIP_NO_ERROR;
}
Expand Down Expand Up @@ -243,6 +245,7 @@ class ReadClientCallback : public ReadClient::Callback

std::unique_ptr<ReadClient> mReadClient;
bool mAutoResubscribe = true;
bool mAutoResubscribeNeeded = false;
};

extern "C" {
Expand Down

0 comments on commit a0dbc95

Please sign in to comment.