Skip to content

Commit 92efde8

Browse files
Handle an (invalid) empty InvokeResponses list. (project-chip#25197)
Without this change, InvokeInteraction could end up not calling either of its callbacks if the server responded with an empty InvokeResponses list.
1 parent b42ee0f commit 92efde8

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

src/controller/InvokeInteraction.h

+5-3
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ InvokeCommandRequest(Messaging::ExchangeManager * aExchangeMgr, const SessionHan
5151
const Optional<uint16_t> & timedInvokeTimeoutMs,
5252
const Optional<System::Clock::Timeout> & responseTimeout = NullOptional)
5353
{
54+
// InvokeCommandRequest expects responses, so cannot happen over a group session.
55+
VerifyOrReturnError(!sessionHandle->IsGroupSession(), CHIP_ERROR_INVALID_ARGUMENT);
56+
5457
app::CommandPathParams commandPath = { endpointId, 0, RequestObjectT::GetClusterId(), RequestObjectT::GetCommandId(),
5558
(app::CommandPathFlags::kEndpointIdValid) };
5659

@@ -91,14 +94,13 @@ InvokeCommandRequest(Messaging::ExchangeManager * aExchangeMgr, const SessionHan
9194
}
9295

9396
/*
94-
* A typed group command invocation function that takes as input a cluster-object representation of a command request and
95-
* callbacks when completed trought the done callback
97+
* A typed group command invocation function that takes as input a cluster-object representation of a command request.
9698
*
9799
* The RequestObjectT is generally expected to be a ClusterName::Commands::CommandName::Type struct, but any object
98100
* that can be encoded using the DataModel::Encode machinery and exposes the GetClusterId() and GetCommandId() functions
99101
* and a ResponseType type is expected to work.
100102
*
101-
* Since this sends a group command, no response will be received and all allocated rescources will be cleared before exing this
103+
* Since this sends a group command, no response will be received and all allocated resources will be cleared before exiting this
102104
* function
103105
*/
104106
template <typename RequestObjectT>

src/controller/TypedCommandCallback.h

+14-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,20 @@ class TypedCommandCallback final : public app::CommandSender::Callback
7272
mOnError(aError);
7373
}
7474

75-
void OnDone(app::CommandSender * apCommandSender) override { mOnDone(apCommandSender); }
75+
void OnDone(app::CommandSender * apCommandSender) override
76+
{
77+
if (!mCalledCallback)
78+
{
79+
// This can happen if the server sends a response with an empty
80+
// InvokeResponses list. Since we are not sending wildcard command
81+
// paths, that's not a valid response and we should treat it as an
82+
// error. Use the error we would have gotten if we in fact expected
83+
// a nonempty list.
84+
OnError(apCommandSender, CHIP_END_OF_TLV);
85+
}
86+
87+
mOnDone(apCommandSender);
88+
}
7689

7790
OnSuccessCallbackType mOnSuccess;
7891
OnErrorCallbackType mOnError;

0 commit comments

Comments
 (0)