From 50f930590d554feea4d971d5916f28fff295999b Mon Sep 17 00:00:00 2001 From: Justin Wood Date: Tue, 8 Oct 2024 20:05:24 -0700 Subject: [PATCH] Fixing deadlock, and not cleaning up on purpose now (#35982) * Fixing deadlock, and not cleaning up on purpose now * Adding this log back * Restyled by clang-format --------- Co-authored-by: Restyled.io --- .../Framework/CHIP/MTRDeviceControllerFactory.mm | 11 +++-------- src/darwin/Framework/CHIP/MTRDevice_XPC.mm | 6 ++++-- 2 files changed, 7 insertions(+), 10 deletions(-) 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]); } }