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 <commits@restyled.io>
diff --git a/src/darwin/Framework/CHIP/MTRDeviceControllerFactory.mm b/src/darwin/Framework/CHIP/MTRDeviceControllerFactory.mm
index 23643d6..815d7ae 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 @@
{
[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 5165e3a..61aad70 100644
--- a/src/darwin/Framework/CHIP/MTRDevice_XPC.mm
+++ b/src/darwin/Framework/CHIP/MTRDevice_XPC.mm
@@ -250,7 +250,8 @@
@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 @@
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]);
}
}