project-chip / connectedhomeip

Matter (formerly Project CHIP) creates more connections between more objects, simplifying development for manufacturers and increasing compatibility for consumers, guided by the Connectivity Standards Alliance.
https://buildwithmatter.com
Apache License 2.0
7.48k stars 2.01k forks source link

Cleanly shutdown IM engine #21233

Open mrjerryjohns opened 2 years ago

mrjerryjohns commented 2 years ago

Problem

The InteractionModelEngine is not cleanly clearing up mpFabricTable and mpExchangeMgr today on Shutdown. Doing so invites a world of problems in the SDK:

  1. ReadClient continues to depend on those members being non-null in its destruction due to its call into in the IM engine in ReadClient::CancelLivenessCheckTimer. This is not a problem in and of itself, but it does alter the paradigm that ReadClient instances can continue to exist well-past IM engine shutdown, which is implied here in InteractionModelEngine::Shutdown:
    //
    // We hold weak references to ReadClient objects. The application ultimately
    // actually owns them, so it's on them to eventually shut them down and free them
    // up.
    //
    // However, we should null out their pointers back to us at the very least so that
    // at destruction time, they won't attempt to reach back here to remove themselves
    // from this list.
    //

We need to fix this, and consequently, fix the various tests that depend on this premise.

  1. Lots of test (TestReadInteraction and TestWriteInteraction) manually Init and Shutdown the engine repeatedly in their tests. At the end of the test, the AppContext does a second Shutdown of the engine as well, which causes problems since Shutdown today is not meant to be called multiple times.
mrjerryjohns commented 2 years ago

FYI @bzbarsky-apple @yunhanw-google

stale[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.