diff --git a/src/darwin/Framework/CHIP/MTRDeviceControllerFactory.mm b/src/darwin/Framework/CHIP/MTRDeviceControllerFactory.mm index 23643d6a52fa18..815d7ae2a9f0f6 100644 --- a/src/darwin/Framework/CHIP/MTRDeviceControllerFactory.mm +++ b/src/darwin/Framework/CHIP/MTRDeviceControllerFactory.mm @@ -73,12 +73,7 @@ static bool sExitHandlerRegistered = false; static void ShutdownOnExit() { - // Depending on the structure of the software, this code might execute *after* the main autorelease pool has exited. - // Therefore, it needs to be enclosed in its own autorelease pool. - @autoreleasepool { - MTR_LOG("ShutdownOnExit invoked on exit"); - [[MTRDeviceControllerFactory sharedInstance] stopControllerFactory]; - } + // Don't do anything here, period } @interface MTRDeviceControllerFactoryParams () @@ -441,8 +436,8 @@ - (void)stopControllerFactory { [self _assertCurrentQueueIsNotMatterQueue]; - while ([_controllers count] != 0) { - [_controllers[0] shutdown]; + for (MTRDeviceController * controller in [_controllers copy]) { + [controller shutdown]; } dispatch_sync(_chipWorkQueue, ^{ diff --git a/src/darwin/Framework/CHIP/MTRDevice_XPC.mm b/src/darwin/Framework/CHIP/MTRDevice_XPC.mm index 5165e3ad26c3f4..61aad700353f08 100644 --- a/src/darwin/Framework/CHIP/MTRDevice_XPC.mm +++ b/src/darwin/Framework/CHIP/MTRDevice_XPC.mm @@ -250,7 +250,8 @@ - (void)_invokeCommandWithEndpointID:(NSNumber *)endpointID @try { [[xpcConnection remoteObjectProxyWithErrorHandler:^(NSError * _Nonnull error) { - MTR_LOG_ERROR("Error: %@", error); + MTR_LOG_ERROR("Invoke error: %@", error); + completion(nil, [NSError errorWithDomain:MTRErrorDomain code:MTRErrorCodeGeneralError userInfo:nil]); }] deviceController:[[self deviceController] uniqueIdentifier] nodeID:[self nodeID] invokeCommandWithEndpointID:endpointID @@ -263,7 +264,8 @@ - (void)_invokeCommandWithEndpointID:(NSNumber *)endpointID serverSideProcessingTimeout:serverSideProcessingTimeout completion:completion]; } @catch (NSException * exception) { - MTR_LOG_ERROR("Exception sending XPC messsage: %@", exception); + MTR_LOG_ERROR("Exception sending XPC message: %@", exception); + completion(nil, [NSError errorWithDomain:MTRErrorDomain code:MTRErrorCodeGeneralError userInfo:nil]); } }