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

[controller] Use short lived CommandSender when no command sender is provided #7041

Merged

Conversation

erjiaqing
Copy link
Contributor

@erjiaqing erjiaqing commented May 21, 2021

Problem

  • The controller::Command has a mpCommandSender object, which is used for App provided command sender object, currently, this is used by python device controller. In however, the controller::Command is designed to be able to encode and send commands for multple used.

Change overview

  • Update template
    • After this PR, the controller::Command's behavior for sending commands is
      1. Allocate a new command sender object, and throw it (make IMEngine manage its lifespan)

Testing

  • The correctness of this test are already covered by various tests, like Darwin test.
  • However, the issue that this PR intent to solve is not covered, and reqiures real tests since it happens in NetworkCommissioning step, and NetworkCommissioning requires available Thread network devices at least.
  • It can be tested by Cirque since we can simulate full commissioning routine on Cirque.
  • Added a simple test in darwin to test if we can reuse the CHIPCluster objects.

@bzbarsky-apple Can you test this on iOS apps? Thanks.

Copy link
Contributor

@woody-apple woody-apple left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! This feels like some unit testing is required here. What unit tests can be put in place?

Copy link
Contributor

@bzbarsky-apple bzbarsky-apple left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this goes back to my question about lifetime of mpCommandSender on Slack. Why do we have it at all if it's single-use but the objects that are using it might be long-lived and get used more than once?

Why can't we just remove the mpCommandSender bit? Where is the restriction on lifetimes if a command sender is caller-provided documented?

What I'd like to see here is:

  1. A better commit message. The PR description is closer, but doesn't really answer my questions above.
  2. Better documentation at the places that provide a command sender, since that sender will still auto-destroy itself and then we will have dangling refs...

@bzbarsky-apple
Copy link
Contributor

As far as testing on iOS, I don't have a setup for that right now, and I will see what I can do. But this definitely feels like something we should be able to have automated tests for.

@erjiaqing
Copy link
Contributor Author

erjiaqing commented May 24, 2021

Thanks! This feels like some unit testing is required here. What unit tests can be put in place?

The code in this change is already covered in various tests, like tests in Darwin platform.

However, the bug it intend to solve is something happened on application side, so it is hard to be covered by UT.

Anyway, added a test in Darwin, although it is not UT, but some kind of end-to-end test.

@erjiaqing erjiaqing force-pushed the im-command-sender-shortlived branch from 49f069e to 486726c Compare May 24, 2021 09:02
@boring-cyborg boring-cyborg bot added the darwin label May 24, 2021
@erjiaqing erjiaqing requested a review from woody-apple May 24, 2021 09:07
@pullapprove pullapprove bot requested a review from sagar-apple May 24, 2021 09:08
@erjiaqing erjiaqing force-pushed the im-command-sender-shortlived branch from 486726c to 3a1f89f Compare May 24, 2021 09:41
@erjiaqing
Copy link
Contributor Author

Thanks! This feels like some unit testing is required here. What unit tests can be put in place?

In this case,

So this goes back to my question about lifetime of mpCommandSender on Slack. Why do we have it at all if it's single-use but the objects that are using it might be long-lived and get used more than once?

Why can't we just remove the mpCommandSender bit? Where is the restriction on lifetimes if a command sender is caller-provided documented?

What I'd like to see here is:

  1. A better commit message. The PR description is closer, but doesn't really answer my questions above.
  2. Better documentation at the places that provide a command sender, since that sender will still auto-destroy itself and then we will have dangling refs...

Removing mpCommandSender from CHIPCluster now, now the commit message is "Not exposing command sender to app", should be clear enough now.

Also added a comment in CommandSender.

@erjiaqing erjiaqing requested a review from bzbarsky-apple May 24, 2021 09:41
@erjiaqing erjiaqing force-pushed the im-command-sender-shortlived branch 2 times, most recently from 0526fd4 to 184aa66 Compare May 24, 2021 10:42
The controller::Command has a mpCommandSender object, which is used by
python device controller. However, the controller::Command is not
designed for single use.

This commit:
- Remove command sender from CHIPClusters
- Add comment in SendCommandRequest that caller SHOULD drop the
reference of CommandSender after SendCommandRequest.

expectation = [self expectationWithDescription:@"ReuseCHIPClusterObjectSecondCall"];

// Reuse the CHIPCluster Object for multiple times.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be a good idea to reuse a number of times larger than CHIP_MAX_NUM_COMMAND_SENDER so that we catch cases when we're leaking senders. Followup is OK for this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#7074 Filed.

@erjiaqing
Copy link
Contributor Author

@andy31415 @Damian-Nordic PTAL, thanks.

@bzbarsky-apple bzbarsky-apple merged commit ebd9e0a into project-chip:master May 26, 2021
nikita-s-wrk pushed a commit to nikita-s-wrk/connectedhomeip that referenced this pull request Sep 23, 2021
…provided (project-chip#7041)

* [controller] Use short lived command sender in CHIPClusters

The controller::Command has a mpCommandSender object, which is used by
python device controller. However, the controller::Command is not
designed for single use.

This commit:
- Remove command sender from CHIPClusters
- Add comment in SendCommandRequest that caller SHOULD drop the
reference of CommandSender after SendCommandRequest.

* Run codegen
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants