Skip to content

Commit 8306353

Browse files
Darwin: Avoid calling DnssdServer::StartServer() when not initialized (project-chip#34465)
* Darwin: Avoid calling DnssdServer::StartServer() when not initialized Look at the SystemState directly instead of relying on _controllers. * Return error from AdvertiseOperational when fabric table is null
1 parent 138fb4f commit 8306353

File tree

3 files changed

+6
-7
lines changed

3 files changed

+6
-7
lines changed

src/app/server/Dnssd.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ void DnssdServer::GetPrimaryOrFallbackMACAddress(chip::MutableByteSpan mac)
188188
/// Set MDNS operational advertisement
189189
CHIP_ERROR DnssdServer::AdvertiseOperational()
190190
{
191-
VerifyOrDie(mFabricTable != nullptr);
191+
VerifyOrReturnError(mFabricTable != nullptr, CHIP_ERROR_INCORRECT_STATE);
192192

193193
for (const FabricInfo & fabricInfo : *mFabricTable)
194194
{

src/controller/CHIPDeviceControllerSystemState.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ class DeviceControllerSystemState
208208
mGroupDataProvider != nullptr && mReportScheduler != nullptr && mTimerDelegate != nullptr &&
209209
mSessionKeystore != nullptr && mSessionResumptionStorage != nullptr && mBDXTransferServer != nullptr;
210210
};
211-
bool IsShutDown() { return mHaveShutDown; }
211+
bool IsShutDown() const { return mHaveShutDown; }
212212

213213
System::Layer * SystemLayer() const { return mSystemLayer; };
214214
Inet::EndPointManager<Inet::TCPEndPoint> * TCPEndPointManager() const { return mTCPEndPointManager; };

src/darwin/Framework/CHIP/MTRDeviceControllerFactory.mm

+4-5
Original file line numberDiff line numberDiff line change
@@ -889,11 +889,10 @@ - (void)resetOperationalAdvertising
889889
// If we're not advertising, then there's no need to reset anything.
890890
VerifyOrReturn(_advertiseOperational);
891891

892-
// If there are no running controllers there will be no advertisements to reset.
893-
{
894-
std::lock_guard lock(_controllersLock);
895-
VerifyOrReturn(_controllers.count > 0);
896-
}
892+
// Ensure the stack is running. We can't look at _controllers to determine this
893+
// reliably because it gets updated early during controller startup from off-queue.
894+
auto systemState = _controllerFactory->GetSystemState();
895+
VerifyOrReturn(systemState != nullptr && !systemState->IsShutDown());
897896

898897
// StartServer() is the only API we have for resetting DNS-SD advertising.
899898
// It sure would be nice if there were a "restart" that was a no-op if the

0 commit comments

Comments
 (0)