diff --git a/src/darwin/Framework/CHIP/MTRControllerFactory.mm b/src/darwin/Framework/CHIP/MTRControllerFactory.mm index 9539a8f6eabdee..3d77b893229d7b 100644 --- a/src/darwin/Framework/CHIP/MTRControllerFactory.mm +++ b/src/darwin/Framework/CHIP/MTRControllerFactory.mm @@ -309,6 +309,14 @@ - (BOOL)startup:(MTRControllerFactoryParams *)startupParams return; } + // Make sure we don't leave a system state running while we have no + // controllers started. This is working around the fact that a system + // state is brought up live on factory init, and not when it comes time + // to actually start a controller, and does not actually clean itself up + // until its refcount (which starts as 0) goes to 0. + _controllerFactory->RetainSystemState(); + _controllerFactory->ReleaseSystemState(); + self->_isRunning = YES; });