-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix ThreadSanitizer failure in controller factory. (#26824)
* Fix ThreadSanitizer failure in controller factory. The failure looks like this: WARNING: ThreadSanitizer: race on NSMutableArray (pid=11619) Read-only access of NSMutableArray at 0x7b0c0005f5b0 by thread T3: #0 -[__NSArrayM countByEnumeratingWithState:objects:count:] <null>:2 (CoreFoundation:x86_64+0x4a338) #1 -[MTRDeviceControllerFactory(InternalMethods) operationalInstanceAdded:] MTRDeviceControllerFactory.mm:855 (Matter:x86_64+0x1fd2a) #2 MTROperationalBrowser::OnBrowse(_DNSServiceRef_t*, unsigned int, unsigned int, int, char const*, char const*, char const*, void*) MTROperationalBrowser.mm:100 (Matter:x86_64+0x20ee63c) #3 handle_browse_response <null>:2 (libsystem_dnssd.dylib:x86_64+0x3733) #4 _dispatch_client_callout <null>:2 (libdispatch.dylib:x86_64+0x3316) Previous modifying access of NSMutableArray at 0x7b0c0005f5b0 by main thread: #0 -[__NSArrayM addObject:] <null>:2 (CoreFoundation:x86_64+0x2457a) #1 -[MTRDeviceControllerFactory createController] MTRDeviceControllerFactory.mm:719 (Matter:x86_64+0x1cee3) #2 -[MTRDeviceControllerFactory createControllerOnExistingFabric:error:] MTRDeviceControllerFactory.mm:534 (Matter:x86_64+0x19792) The basic problem is that we are in the middle of adding an object to _controllers on the API consumer thread when on the Matter thread we get our browse notification. The changes here don't aim to lock around all access to _controllers, but just to make sure that our mutations of it can't race with the access on the Matter thread. More coarse locking would need to be done very carefully, given the amount of dispath_sync to the Matter thread we have going on. * Address review comments.
- Loading branch information
1 parent
1ae2886
commit 84e1bd2
Showing
4 changed files
with
72 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters