Skip to content

Commit 1548862

Browse files
bzbarsky-applepull[bot]
authored andcommitted
Handle an (invalid) empty WriteResponses list. (#25229)
Without this change, WriteInteraction could end up not calling either of its callbacks if the server responded to a non-group non-wildcard write with an empty WriteResponses list.
1 parent 4b12d7a commit 1548862

1 file changed

Lines changed: 14 additions & 3 deletions

File tree

src/controller/WriteInteraction.h

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ class WriteCallback final : public app::WriteClient::Callback
5050
using OnErrorCallbackType = std::function<void(const app::ConcreteAttributePath * path, CHIP_ERROR err)>;
5151
using OnDoneCallbackType = std::function<void(app::WriteClient *)>;
5252

53-
WriteCallback(OnSuccessCallbackType aOnSuccess, OnErrorCallbackType aOnError, OnDoneCallbackType aOnDone) :
54-
mOnSuccess(aOnSuccess), mOnError(aOnError), mOnDone(aOnDone), mCallback(this)
53+
WriteCallback(OnSuccessCallbackType aOnSuccess, OnErrorCallbackType aOnError, OnDoneCallbackType aOnDone, bool aIsGroupWrite) :
54+
mOnSuccess(aOnSuccess), mOnError(aOnError), mOnDone(aOnDone), mIsGroupWrite(aIsGroupWrite), mCallback(this)
5555
{}
5656

5757
app::WriteClient::Callback * GetChunkedCallback() { return &mCallback; }
@@ -88,6 +88,16 @@ class WriteCallback final : public app::WriteClient::Callback
8888

8989
void OnDone(app::WriteClient * apWriteClient) override
9090
{
91+
if (!mIsGroupWrite && !mCalledCallback)
92+
{
93+
// This can happen if the server sends a response with an empty
94+
// WriteResponses list. Since we are not sending wildcard write
95+
// paths, that's not a valid response and we should treat it as an
96+
// error. Use the error we would have gotten if we in fact expected
97+
// a nonempty list.
98+
OnError(apWriteClient, CHIP_END_OF_TLV);
99+
}
100+
91101
if (mOnDone != nullptr)
92102
{
93103
mOnDone(apWriteClient);
@@ -104,6 +114,7 @@ class WriteCallback final : public app::WriteClient::Callback
104114
OnDoneCallbackType mOnDone = nullptr;
105115

106116
bool mCalledCallback = false;
117+
bool mIsGroupWrite = false;
107118

108119
app::ChunkedWriteCallback mCallback;
109120
};
@@ -121,7 +132,7 @@ CHIP_ERROR WriteAttribute(const SessionHandle & sessionHandle, chip::EndpointId
121132
WriteCallback::OnDoneCallbackType onDoneCb = nullptr,
122133
const Optional<DataVersion> & aDataVersion = NullOptional)
123134
{
124-
auto callback = Platform::MakeUnique<WriteCallback>(onSuccessCb, onErrorCb, onDoneCb);
135+
auto callback = Platform::MakeUnique<WriteCallback>(onSuccessCb, onErrorCb, onDoneCb, sessionHandle->IsGroupSession());
125136
VerifyOrReturnError(callback != nullptr, CHIP_ERROR_NO_MEMORY);
126137

127138
auto client = Platform::MakeUnique<app::WriteClient>(app::InteractionModelEngine::GetInstance()->GetExchangeManager(),

0 commit comments

Comments
 (0)