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

Fix shutdown ordering in DeviceController. #7430

Merged
merged 1 commit into from
Jun 8, 2021
Merged
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
23 changes: 14 additions & 9 deletions src/controller/CHIPDeviceController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,20 @@ CHIP_ERROR DeviceController::Shutdown()

ChipLogDetail(Controller, "Shutting down the controller");

#if CONFIG_DEVICE_LAYER
// Start by shutting down the PlatformManager. This will ensure, with
// reasonable synchronization, that we stop processing of incoming messages
// before doing any other shutdown work. Otherwise we can end up trying to
// process incoming messages in a partially shut down state, which is not
// great at all.
ReturnErrorOnFailure(DeviceLayer::PlatformMgr().Shutdown());
#else
mInetLayer->Shutdown();
mSystemLayer->Shutdown();
chip::Platform::Delete(mInetLayer);
chip::Platform::Delete(mSystemLayer);
#endif // CONFIG_DEVICE_LAYER

mState = State::NotInitialized;

// TODO(#6668): Some exchange has leak, shutting down ExchangeManager will cause a assert fail.
Expand All @@ -304,15 +318,6 @@ CHIP_ERROR DeviceController::Shutdown()
mSessionMgr->Shutdown();
}

#if CONFIG_DEVICE_LAYER
ReturnErrorOnFailure(DeviceLayer::PlatformMgr().Shutdown());
#else
mInetLayer->Shutdown();
mSystemLayer->Shutdown();
chip::Platform::Delete(mInetLayer);
chip::Platform::Delete(mSystemLayer);
#endif // CONFIG_DEVICE_LAYER

mSystemLayer = nullptr;
mInetLayer = nullptr;
mStorageDelegate = nullptr;
Expand Down