-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Data model objects can be accessed before the data model server is initialized #15295
Comments
Well, there is a data race here. The init code linked to seems to be doing the following:
Now I added asserts to catch this race in #15152 but could not figure out how to do the relevant "lock is not held" checks on Zephyr.... The second bullet of the proposed solution sounds good, in terms of ensuring that we're done touching Matter bits before the separate Matter thread starts running.... |
But also, the various example apps that are doing |
Oh, and CI is not catching this stuff because the "linux" impl we use in CI for Linux and Darwin does not use So I guess we need to enforce at minimum that |
Yes, that seems to solve my issue locally. I just moved event loop start after all application initialization is over. |
That said, its annoying that the way this event is generated forces all the init work to happen on the main thread, not the Matter thread.... |
Problem
On nrfconnect I did observation that
StartUp
event is generated successfully after the boot if the device is not commissioned and the generation fails if the device was previously commissioned. The root cause of that is the event generation is scheduled by theInitChipStack
and it uses data model objects even before data model server was initialized. It looks like some time race conditions may occur and sometimes data model will manage to be initialized on time and sometimes not.Generation schedule: https://github.com/project-chip/connectedhomeip/blob/master/src/include/platform/internal/GenericPlatformManagerImpl.cpp#L126
Delegates set by data model: https://github.com/project-chip/connectedhomeip/blob/master/src/include/platform/internal/GenericPlatformManagerImpl.cpp#L297
Call of
InitChipStack
: https://github.com/project-chip/connectedhomeip/blob/master/examples/lock-app/nrfconnect/main/main.cpp#L46Call of data model server init: https://github.com/project-chip/connectedhomeip/blob/master/examples/lock-app/nrfconnect/main/AppTask.cpp#L102
Problem was exposed by the cluster events behavior, but I believe it should not happen that CHIP events loop is started and processed events may try accessing data model objects, before data model server was initialized. Many platforms implement it in the similar way, so probably it affects not only nrfconnect.
Proposed Solution
HandleDeviceRebooted
(https://github.com/project-chip/connectedhomeip/blob/master/src/include/platform/internal/GenericPlatformManagerImpl.cpp#L294).The text was updated successfully, but these errors were encountered: