Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make it easier to catch bugs in async command handling. #25402

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/app/CommandHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ void CommandHandler::OnInvokeCommandRequest(Messaging::ExchangeContext * ec, con
StatusResponse::Send(status, mExchangeCtx.Get(), false /*aExpectResponse*/);
mSentStatusResponse = true;
}

mGoneAsync = true;
}

Status CommandHandler::ProcessInvokeRequest(System::PacketBufferHandle && payload, bool isTimedInvoke)
Expand Down Expand Up @@ -577,6 +579,7 @@ TLV::TLVWriter * CommandHandler::GetCommandDataIBTLVWriter()

FabricIndex CommandHandler::GetAccessingFabricIndex() const
{
VerifyOrDie(!mGoneAsync);
return mExchangeCtx->GetSessionHandle()->GetFabricIndex();
}

Expand Down
23 changes: 22 additions & 1 deletion src/app/CommandHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,13 @@ class CommandHandler : public Messaging::ExchangeDelegate
CHIP_ERROR PrepareStatus(const ConcreteCommandPath & aCommandPath);
CHIP_ERROR FinishStatus();
TLV::TLVWriter * GetCommandDataIBTLVWriter();

/**
* GetAccessingFabricIndex() may only be called during synchronous command
* processing. Anything that runs async (while holding a
* CommandHandler::Handle or equivalent) must not call this method, because
* it will not work right if the session we're using was evicted.
*/
FabricIndex GetAccessingFabricIndex() const;

/**
Expand Down Expand Up @@ -272,7 +279,17 @@ class CommandHandler : public Messaging::ExchangeDelegate
msgContext->FlushAcks();
}

Access::SubjectDescriptor GetSubjectDescriptor() const { return mExchangeCtx->GetSessionHandle()->GetSubjectDescriptor(); }
/**
* GetSubjectDescriptor() may only be called during synchronous command
* processing. Anything that runs async (while holding a
* CommandHandler::Handle or equivalent) must not call this method, because
* it might not work right if the session we're using was evicted.
*/
Access::SubjectDescriptor GetSubjectDescriptor() const
{
VerifyOrDie(!mGoneAsync);
return mExchangeCtx->GetSessionHandle()->GetSubjectDescriptor();
}

private:
friend class TestCommandInteraction;
Expand Down Expand Up @@ -394,6 +411,10 @@ class CommandHandler : public Messaging::ExchangeDelegate
chip::System::PacketBufferTLVWriter mCommandMessageWriter;
TLV::TLVWriter mBackupWriter;
bool mBufferAllocated = false;
// If mGoneAsync is true, we have finished out initial processing of the
// incoming invoke. After this point, our session could go away at any
// time.
bool mGoneAsync = false;
};

} // namespace app
Expand Down