diff --git a/src/app/server/Server.cpp b/src/app/server/Server.cpp index 4330446f410698..6e8799911c554b 100644 --- a/src/app/server/Server.cpp +++ b/src/app/server/Server.cpp @@ -125,9 +125,6 @@ CHIP_ERROR Server::Init(const ServerInitParams & initParams) // TODO(16969): Remove chip::Platform::MemoryInit() call from Server class, it belongs to outer code chip::Platform::MemoryInit(); - SuccessOrExit(err = mCommissioningWindowManager.Init(this)); - mCommissioningWindowManager.SetAppDelegate(initParams.appDelegate); - // Initialize PersistentStorageDelegate-based storage mDeviceStorage = initParams.persistentStorageDelegate; mSessionResumptionStorage = initParams.sessionResumptionStorage; @@ -165,9 +162,6 @@ CHIP_ERROR Server::Init(const ServerInitParams & initParams) mAclStorage = initParams.aclStorage; SuccessOrExit(err = mAclStorage->Init(*mDeviceStorage, mFabrics.begin(), mFabrics.end())); - app::DnssdServer::Instance().SetFabricTable(&mFabrics); - app::DnssdServer::Instance().SetCommissioningModeProvider(&mCommissioningWindowManager); - mGroupsProvider = initParams.groupDataProvider; SetGroupDataProvider(mGroupsProvider); @@ -221,6 +215,12 @@ CHIP_ERROR Server::Init(const ServerInitParams & initParams) err = mUnsolicitedStatusHandler.Init(&mExchangeMgr); SuccessOrExit(err); + SuccessOrExit(err = mCommissioningWindowManager.Init(this)); + mCommissioningWindowManager.SetAppDelegate(initParams.appDelegate); + + app::DnssdServer::Instance().SetFabricTable(&mFabrics); + app::DnssdServer::Instance().SetCommissioningModeProvider(&mCommissioningWindowManager); + err = chip::app::InteractionModelEngine::GetInstance()->Init(&mExchangeMgr, &GetFabricTable()); SuccessOrExit(err); @@ -424,6 +424,7 @@ void Server::Shutdown() chip::Dnssd::Resolver::Instance().Shutdown(); chip::app::InteractionModelEngine::GetInstance()->Shutdown(); + mCommissioningWindowManager.Shutdown(); mMessageCounterManager.Shutdown(); mExchangeMgr.Shutdown(); mSessions.Shutdown(); @@ -431,7 +432,6 @@ void Server::Shutdown() mAccessControl.Finish(); Credentials::SetGroupDataProvider(nullptr); mAttributePersister.Shutdown(); - mCommissioningWindowManager.Shutdown(); // TODO(16969): Remove chip::Platform::MemoryInit() call from Server class, it belongs to outer code chip::Platform::MemoryShutdown(); } diff --git a/src/transport/SessionManager.cpp b/src/transport/SessionManager.cpp index bd84ab651ba84d..bdc8573059b81d 100644 --- a/src/transport/SessionManager.cpp +++ b/src/transport/SessionManager.cpp @@ -112,6 +112,9 @@ void SessionManager::Shutdown() mFabricTable = nullptr; } + // Ensure that we don't create new sessions as we iterate our session table. + mState = State::kNotReady; + mSecureSessions.ForEachSession([&](auto session) { session->MarkForEviction(); return Loop::Continue; @@ -119,7 +122,6 @@ void SessionManager::Shutdown() mMessageCounterManager = nullptr; - mState = State::kNotReady; mSystemLayer = nullptr; mTransportMgr = nullptr; mCB = nullptr; @@ -386,6 +388,7 @@ void SessionManager::ExpireAllPASESessions() Optional SessionManager::AllocateSession(SecureSession::Type secureSessionType, const ScopedNodeId & sessionEvictionHint) { + VerifyOrReturnValue(mState == State::kInitialized, NullOptional); return mSecureSessions.CreateNewSecureSession(secureSessionType, sessionEvictionHint); }