Skip to content

Commit

Permalink
Fix a race in CHIPDeviceController while shutting down (#8803)
Browse files Browse the repository at this point in the history
  • Loading branch information
sagar-apple authored and pull[bot] committed Sep 8, 2021
1 parent 9685f7f commit 3021161
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/darwin/Framework/CHIP/CHIPDeviceController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@

@interface CHIPDeviceController ()

@property (nonatomic, readonly, strong, nonnull) NSRecursiveLock * lock;

// queue used to serialize all work performed by the CHIPDeviceController
@property (atomic, readonly) dispatch_queue_t chipWorkQueue;

Expand Down Expand Up @@ -377,18 +375,21 @@ - (BOOL)getConnectedDevice:(uint64_t)deviceID
queue:(dispatch_queue_t)queue
completionHandler:(CHIPDeviceConnectionCallback)completionHandler
{
__block CHIP_ERROR errorCode = CHIP_ERROR_INCORRECT_STATE;
if (![self isRunning]) {
NSError * error;
[self checkForError:CHIP_ERROR_INCORRECT_STATE logMsg:kErrorNotRunning error:&error];
[self checkForError:errorCode logMsg:kErrorNotRunning error:&error];
dispatch_async(queue, ^{
completionHandler(nil, error);
});
return NO;
}

dispatch_async(_chipWorkQueue, ^{
CHIPDeviceConnectionBridge * connectionBridge = new CHIPDeviceConnectionBridge(completionHandler, queue);
CHIP_ERROR errorCode = connectionBridge->connect(self->_cppCommissioner, deviceID);
if ([self isRunning]) {
CHIPDeviceConnectionBridge * connectionBridge = new CHIPDeviceConnectionBridge(completionHandler, queue);
errorCode = connectionBridge->connect(self->_cppCommissioner, deviceID);
}

NSError * error;
if ([self checkForError:errorCode logMsg:kErrorGetPairedDevice error:&error]) {
Expand Down

0 comments on commit 3021161

Please sign in to comment.