From 5e97be8b1cfdfba7918d62e77c2ef19a74d4e739 Mon Sep 17 00:00:00 2001 From: makadaw Date: Wed, 24 May 2017 12:45:55 -0700 Subject: [PATCH] Fix data race on read/write _instance variable in ModuleData class Summary: Thanks for submitting a PR! Please read these instructions carefully: - [ ] Explain the **motivation** for making this change. - [ ] Provide a **test plan** demonstrating that the code is solid. - [ ] Match the **code formatting** of the rest of the codebase. - [ ] Target the `master` branch, NOT a "stable" branch. What existing problem does the pull request solve? XCode [Thread Sanitizer](https://clang.llvm.org/docs/ThreadSanitizer.html) find race condition while read/write `_instance` variable in RCTModuleData class. A bridge can check `hasInstance` method while instance writes. All tests passed on my device. These changes remove data race, you can turn it in scheme configuration ![](https://www.shinobicontrols.com/wp-content/uploads/2016/08/Enable_Sanitizer.png) Closes https://github.com/facebook/react-native/pull/13757 Differential Revision: D4994041 Pulled By: javache fbshipit-source-id: 631cd59bbcbde193937d8baf8358ff6868717a2e --- React/Base/RCTModuleData.mm | 1 + 1 file changed, 1 insertion(+) diff --git a/React/Base/RCTModuleData.mm b/React/Base/RCTModuleData.mm index cc70c13e1..e4254d0c2 100644 --- a/React/Base/RCTModuleData.mm +++ b/React/Base/RCTModuleData.mm @@ -214,6 +214,7 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init); - (BOOL)hasInstance { + std::unique_lock lock(_instanceLock); return _instance != nil; }