-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Manage DataModel::Provider lifecycle in DeviceControllerFactory #42272
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
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request correctly addresses a dangling pointer issue in the InteractionModelEngine singleton by ensuring the DataModelProvider is properly shut down and reset. This is a crucial fix for ensuring hermetic behavior in unit tests. The added test case effectively validates this fix.
|
PR #42272: Size comparison from 078ba11 to f404cad Full report (21 builds for bl602, bl702, bl702l, cc13x4_26x4, cc32xx, psoc6, qpg, realtek, stm32)
|
|
PR #42272: Size comparison from 078ba11 to 73b6449 Full report (34 builds for bl602, bl702, bl702l, cc13x4_26x4, cc32xx, efr32, esp32, nxp, psoc6, qpg, realtek, stm32, telink)
|
|
PR #42272: Size comparison from 078ba11 to 97c267e Full report (34 builds for bl602, bl702, bl702l, cc13x4_26x4, cc32xx, efr32, esp32, nxp, psoc6, qpg, realtek, stm32, telink)
|
|
PR #42272: Size comparison from 078ba11 to 7594633 Full report (35 builds for bl602, bl702, bl702l, cc13x4_26x4, cc32xx, efr32, esp32, nrfconnect, nxp, psoc6, qpg, realtek, stm32, telink)
|
src/app/InteractionModelEngine.cpp
Outdated
| // mpFabricTable = nullptr; | ||
| // mpExchangeMgr = nullptr; | ||
|
|
||
| if (mDataModelProvider) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please see discussion in #42149
Since IME startup is not what starts the data model provider, it's weird to have shutdown shutting it down.... We need to figure out whether the startup needs to move or whether the clearing of the data model provider needs to happen in the same scope as the setting (i.e. in the relevant test scope) as needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ack. Thank you for the reference to the discussion.
This naive approach was based on InteractionModelEngine::SetDataModelProvider calling Shutdown on the old DataModel::Provider.
I reached out offline to @andy31415 for guidance.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I think we all agree the current semantics are bad.... If this is blocking something, we could land it as a stopgap, but long-term we really don't want shutdown shutting down things that init/startup did not start up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is currently blocking testing with code-driven data model provider, which in turn blocks the use of code-driven data model provider.
That said, this can't land as-is for the same reasons you mentioned. Will need to wait for additional discussions with @andy31415 to clarify intended use.
... but long-term we really don't want shutdown shutting down things that init/startup did not start up.
Would you mind clarifying what you mean by this? As far as I can see InteractionModelEngine::SetDataModelProvider does initialize the DataModel::Provider (via call to Startup).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I guess you mean InteractionModelEngine::Init/Shutdown ... fair enough.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess for my uses, calling SetDataModelProvider with a nullptr may unblock work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the controller factory, if init sets to non-null, shutdown can set to null ... we should generally be symmetric.
|
PR #42272: Size comparison from ba864e9 to fb240d3 Full report (5 builds for cc32xx, realtek, stm32)
|
* On Shutdown call InteractionModelEngine::SetDataModelProvider with nullptr * Cache DataModel::Provider within DeviceControllerFactory to allow it it reinitialize.
Manage DataModel::Provider lifecycle in DeviceControllerFactory
nullptr
it reinitialize.
Summary
InteractionModelEngine is a global singleton and does not get re-instantiated for each test. DataModelProvider delegate is never cleaned up during Shutdown, thus the pointer leaks across tests. During a second test InteractionModelEngine::SetDataModelProvider() will attempt to call Shutdown on the existing pointer. If DataModelProvider is local to the test this will crash as the old DataModelProvider would have been deleted.
Testing
CI
Readability checklist
The checklist below will help the reviewer finish PR review in time and keep the
code readable:
descriptive
“When in Rome…”
rule (coding style)
See: Pull Request Guidelines