Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Data race in -[RCTBatchedBridge isBatchActive] #13485

Closed
makadaw opened this issue Apr 13, 2017 · 0 comments
Closed

Data race in -[RCTBatchedBridge isBatchActive] #13485

makadaw opened this issue Apr 13, 2017 · 0 comments
Labels
Resolution: Locked This issue was locked by the bot.

Comments

@makadaw
Copy link
Contributor

makadaw commented Apr 13, 2017

On last react-native 0.43.2 Xcode find data race. This can affect layout performance

Explain what you did, what you expected to happen, and what actually happens.

Reproduction Steps and Sample Code

Run RN project with on ThreadSanitizer in Xcode. Display any view with a bridge.
Get next console log

==================
WARNING: ThreadSanitizer: data race (pid=91001)
  Read of size 1 at 0x7d380005e328 by thread T30:
    #0 -[RCTBatchedBridge isBatchActive] RCTBatchedBridge.m:1099 (Test:x86_64+0x1036ce8fc)
    #1 -[RCTUIManager setNeedsLayout] RCTUIManager.m:1205 (Test:x86_64+0x1038c3bd3)
    #2 __45-[RCTUIManager setAvailableSize:forRootView:]_block_invoke RCTUIManager.m:439 (Test:x86_64+0x1038ac4c1)
    #3 __tsan::invoke_and_release_block(void*) <null>:3352480 (libclang_rt.tsan_iossim_dynamic.dylib:x86_64+0x6043b)
    #4 _dispatch_client_callout <null>:3352480 (libdispatch.dylib:x86_64+0x2b05b)

  Previous write of size 1 at 0x7d380005e328 by thread T25:
    #0 -[RCTBatchedBridge handleBuffer:batchEnded:] RCTBatchedBridge.m:934 (Test:x86_64+0x1036c9b02)
    #1 -[RCTBatchedBridge _processResponse:error:] RCTBatchedBridge.m:914 (Test:x86_64+0x1036c93ca)
    #2 __69-[RCTBatchedBridge _actuallyInvokeAndProcessModule:method:arguments:]_block_invoke RCTBatchedBridge.m:884 (Test:x86_64+0x1036c85ed)
    #3 __65-[RCTJSCExecutor _executeJSCall:arguments:unwrapResult:callback:]_block_invoke RCTJSCExecutor.mm:662 (Test:x86_64+0x103752b08)
    #4 -[RCTJSCExecutor executeBlockOnJavaScriptQueue:] RCTJSCExecutor.mm:798 (Test:x86_64+0x1037541da)
2017-04-13 10:49:13.400 Test[91001:14246437] [BCRLocalizationModule] Translating Tag ios_appsearch_guests_love_filter_facilities
    #5 -[RCTJSCExecutor _executeJSCall:arguments:unwrapResult:callback:] RCTJSCExecutor.mm:599 Test:x86_64+0x103750c20)
    #6 -[RCTJSCExecutor _callFunctionOnModule:method:arguments:returnValue:unwrapResult:callback:] RCTJSCExecutor.mm:571 (Test:x86_64+0x10374ff06)
    #7 -[RCTJSCExecutor callFunctionOnModule:method:arguments:callback:] RCTJSCExecutor.mm:576 (Test:x86_64+0x1037501c4)
    #8 -[RCTBatchedBridge _actuallyInvokeAndProcessModule:method:arguments:] RCTBatchedBridge.m:880 (Test:x86_64+0x1036c8431)
    #9 __57-[RCTBatchedBridge enqueueJSCall:method:args:completion:]_block_invoke RCTBatchedBridge.m:764 (Test:x86_64+0x1036c42e5)
    #10 __40-[RCTBatchedBridge dispatchBlock:queue:]_block_invoke RCTBatchedBridge.m:662 (Test:x86_64+0x1036c1d7f)
2017-04-13 10:49:13.430 Test[91001:14246437] [BCRLocalizationModule] Translating Tag ios_explore_hello
    #11 -[RCTJSCExecutor executeBlockOnJavaScriptQueue:] RCTJSCExecutor.mm:798 (Test:x86_64+0x1037541da)
    #12 __NSThreadPerformPerform <null>:3352480 (Foundation:x86_64+0x6de50)
    #13 __NSThread__start__ <null>:3352480 (Foundation:x86_64+0x30fb0)

  Location is heap block of size 216 at 0x7d380005e2c0 allocated by main thread:
    #0 calloc <null>:3352512 (libclang_rt.tsan_iossim_dynamic.dylib:x86_64+0x44222)
    #1 class_createInstance <null>:3352512 (libobjc.A.dylib:x86_64+0xfba0)
    #2 -[RCTBridge setUp] RCTBridge.m:297 (Test:x86_64+0x1036d7ad3)
    #3 -[RCTBridge initWithDelegate:bundleURL:moduleProvider:launchOptions:] RCTBridge.m:192 (Test:x86_64+0x1036d5eb2)
    #4 -[RCTBridge initWithDelegate:launchOptions:] RCTBridge.m:165 (Test:x86_64+0x1036d57c4)
    #5 -[RNBridgeProvider bridge] RNBridgeProvider.m:48 (Test:x86_64+0x103ba4831)
    #6 -[BCRectNativeFactory createTestViewViewController] BCRectNativeFactory.m:42 (Test:x86_64+0x103b89594)
    #7 -[BCReactNativeTestHelper testController] BCReactNativeTestHelper.m:31 (Test:x86_64+0x1001c19c6)
    #8 __64+[BCViewControllerMenuItemFactory createReactNativeTestMenuItem]_block_invoke BCViewControllerMenuItemFactory.m:241 (Test:x86_64+0x101aa52ee)
    #9 -[BCTabbarMoreViewController openItem:] BCTabbarMoreViewController.m:146 (Test:x86_64+0x1000bb4fa)
    #10 -[BCTabbarMoreViewController tableView:didSelectRowAtIndexPath:] BCTabbarMoreViewController.m:139 (Test:x86_64+0x1000bb3a6)
    #11 -[UITableView _selectRowAtIndexPath:animated:scrollPosition:notifyDelegate:] <null>:3352512 (UIKit:x86_64+0x17edcc)
    #12 start <null>:3352512 (libdyld.dylib:x86_64+0x465c)

  Thread T30 (tid=14254905, running) created by thread T-1
    [failed to restore the stack]

  Thread T25 (tid=14246437, running) created by main thread at:
    #0 pthread_create <null>:3352560 (libclang_rt.tsan_iossim_dynamic.dylib:x86_64+0x2689d)
    #1 -[NSThread start] <null>:3352560 (Foundation:x86_64+0x30acc)
    #2 -[RCTJSCExecutor initWithUseCustomJSCLibrary:] RCTJSCExecutor.mm:246 (Test:x86_64+0x1037450ca)
    #3 -[RCTJSCExecutor init] RCTJSCExecutor.mm:236 (Test:x86_64+0x103744d59)
    #4 -[RCTBatchedBridge initModulesWithDispatchGroup:] RCTBatchedBridge.m:322 (Test:x86_64+0x1036b9661)
    #5 -[RCTBatchedBridge start] RCTBatchedBridge.m:129 (Test:x86_64+0x1036b3487)
    #6 -[RCTBridge setUp] RCTBridge.m:298 (Test:x86_64+0x1036d7b58)
    #7 -[RCTBridge initWithDelegate:bundleURL:moduleProvider:launchOptions:] RCTBridge.m:192 (Test:x86_64+0x1036d5eb2)
    #8 -[RCTBridge initWithDelegate:launchOptions:] RCTBridge.m:165 (Test:x86_64+0x1036d57c4)
    #9 -[RNBridgeProvider bridge] RNBridgeProvider.m:48 (Test:x86_64+0x103ba4831)
    #10 -[BCRectNativeFactory createTestViewViewController] BCRectNativeFactory.m:42 (Test:x86_64+0x103b89594)
    #11 -[BCReactNativeTestHelper testController] BCReactNativeTestHelper.m:31 (Test:x86_64+0x1001c19c6)
    #12 __64+[BCViewControllerMenuItemFactory createReactNativeTestMenuItem]_block_invoke BCViewControllerMenuItemFactory.m:241 (Test:x86_64+0x101aa52ee)
    #13 -[BCTabbarMoreViewController openItem:] BCTabbarMoreViewController.m:146 (Test:x86_64+0x1000bb4fa)
2017-04-13 10:49:13.443 Test[91001:14246437] [BCRLocalizationModule] Translating Pluralized Tag ios_reviews_subheader_share_photos_done for 3
    #14 -[BCTabbarMoreViewController tableView:didSelectRowAtIndexPath:] BCTabbarMoreViewController.m:139 (Test:x86_64+0x1000bb3a6)
    #15 -[UITableView _selectRowAtIndexPath:animated:scrollPosition:notifyDelegate:] <null>:3352560 (UIKit:x86_64+0x17edcc)
    #16 start <null>:3352560 (libdyld.dylib:x86_64+0x465c)

SUMMARY: ThreadSanitizer: data race RCTBatchedBridge.m:1099 in -[RCTBatchedBridge isBatchActive]
==================

Thread info:

thread #34: tid = 0xd98339, 0x00000001115cde90 libclang_rt.tsan_iossim_dynamic.dylib`__tsan_on_report, queue = 'com.facebook.react.ShadowQueue', stop reason = Data race detected

{
  "all_addresses_are_same" : true,
  "description" : "Data race",
  "instrumentation_class" : "ThreadSanitizer",
  "issue_type" : "data-race",
  "location_description" : "Location is a 216-byte heap object at 0x7d380005e2c0",
  "locs" : [
    {
      "address" : 0,
      "file_descriptor" : 0,
      "index" : 0,
      "size" : 216,
      "start" : 137679472026304,
      "suppressable" : 0,
      "thread_id" : 28,
      "trace" : [
        4586185251,
        4711140257,
        4520749780,
        4520742579,
        4520740805,
        4525783090,
        4525671829,
        4465084871
      ],
      "type" : "heap"
    }
  ],
  "memory_address" : 137679472026408,
  "mops" : [
    {
      "address" : 137679472026408,
      "index" : 0,
      "is_atomic" : false,
      "is_write" : false,
      "size" : 1,
      "thread_id" : 34,
      "trace" : [
        4520712445,
        4522765268,
        4522669250,
        4586300476,
        4742209628
      ]
    },
    {
      "address" : 137679472026408,
      "index" : 1,
      "is_atomic" : false,
      "is_write" : true,
      "size" : 1,
      "thread_id" : 26,
      "trace" : [
        4520692483,
        4520690635,
        4520687086,
        4521253641,
        4521259483,
        4521245729,
        4521242375,
        4521243077
      ]
    }
  ],
  "mutexes" : [

  ],
  "report_count" : 0,
  "sleep_trace" : [

  ],
  "stacks" : [

  ],
  "stop_description" : "Data race detected",
  "summary" : "Data race in -[RCTBatchedBridge isBatchActive] at 0x7d380005e2c0",
  "threads" : [
    {
      "index" : 0,
      "name" : "",
      "parent_thread_id" : 0,
      "running" : 1,
      "thread_id" : 34,
      "thread_os_id" : 14254905,
      "trace" : [

      ]
    },
    {
      "index" : 1,
      "name" : "",
      "parent_thread_id" : 28,
      "running" : 1,
      "thread_id" : 26,
      "thread_os_id" : 14246437,
      "trace" : [
        4586064030,
        4639357645,
        4521197771,
        4521196890,
        4520625762,
        4520600712,
        4520749913,
        4520742579
      ]
    },
    {
      "index" : 2,
      "name" : "",
      "parent_thread_id" : 28,
      "running" : 1,
      "thread_id" : 28,
      "thread_os_id" : 91001,
      "trace" : [

      ]
    }
  ],
  "unique_tids" : [

  ]
}

Solution

Lock write of this variable

Additional Information

  • React Native version: 0.43.2
  • Platform: iOS
  • Development Operating System: macOS 10.12
  • Dev tools: Xcode 4.3, iPhone 7 Simulator with iOS 10.3
Maxwell2022 pushed a commit to Maxwell2022/react-native that referenced this issue Apr 19, 2017
Summary:
Issue Fix: facebook#13485

Yet another race condition that was found by XCode's Thread Sanitizer.
Happens because wasBatchActive is read/write from multiple threads at the same time

- opened UIExplorer and see it works
- npm run test pass
- tested on own project as well

Signed CLA
Closes facebook#13505

Differential Revision: D4906096

Pulled By: javache

fbshipit-source-id: 5d4329aafcfe9491ce0188fa1e2dd71e09b31031
thotegowda pushed a commit to thotegowda/react-native that referenced this issue May 7, 2017
Summary:
Issue Fix: facebook#13485

Yet another race condition that was found by XCode's Thread Sanitizer.
Happens because wasBatchActive is read/write from multiple threads at the same time

- opened UIExplorer and see it works
- npm run test pass
- tested on own project as well

Signed CLA
Closes facebook#13505

Differential Revision: D4906096

Pulled By: javache

fbshipit-source-id: 5d4329aafcfe9491ce0188fa1e2dd71e09b31031
@facebook facebook locked as resolved and limited conversation to collaborators May 24, 2018
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Jul 18, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests

2 participants