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

timing fix for RCTCxxBridge.executeApplicationScript #25991

Closed
wants to merge 1 commit into from

Conversation

ahimberg
Copy link
Contributor

@ahimberg ahimberg commented Aug 9, 2019

Summary

In one of our test apps (actually on Mac not iOS, but same code) we very consistently crash in RCTCxxBridge.executeApplicationScript when js debugging, due to a timing issue where another thread has reset _reactInstance in between the null check on self->_reactInstance and usage of it on these lines:

    } else if (self->_reactInstance) {
      self->_reactInstance->loadScriptFromString(std::make_unique<NSDataBigString>(script),

The thread doing the reset is doing so switching the executorClass to WebSocketExecutor.
In the scenario we crash, the packager has a bundle ready and quickly returns it, though its a 34MB string being passed to NSDataBigString which must be taking long enough for the other thread to get a chance to reset.

Changelog

[iOS] [Fixed] - Fix crash in RCTCxxBridge.executeApplicationScript

Test Plan

Ran apple code path in normal from bundle file and js debugging scenarios.

@ahimberg ahimberg requested a review from mhorowitz as a code owner August 9, 2019 02:01
@facebook-github-bot
Copy link
Contributor

Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need the corporate CLA signed.

If you have received this in error or have any questions, please contact us at cla@fb.com. Thanks!

@react-native-bot react-native-bot added Bug Platform: iOS iOS applications. labels Aug 9, 2019
@ahimberg
Copy link
Contributor Author

ahimberg commented Aug 9, 2019

alternatively an additional null check could be added after creating the NSDataBigString, this seemed a little cleaner

@zhongwuzw
Copy link
Contributor

@ahimberg Hi, thanks for the PR! Would you mind show the crash stack backtrace? I think we already ensure read and write it on JS thread.

@ahimberg
Copy link
Contributor Author

ahimberg commented Aug 9, 2019

Sure, this is the callstack where I see the crash (the JS thread is where the reset happened):

Thread 14 Queue : com.apple.root.user-interactive-qos (concurrent)
#0	0x000000000000f000 in 0x0000f000 ()
#1	0x0000000100323fd4 in ::__51-[RCTCxxBridge executeApplicationScript:url:async:]_block_invoke() at src/react-native/React/CxxBridge/RCTCxxBridge.mm:1317
#2	0x000000010032abfe in decltype(std::__1::forward<void () block_pointer __strong&>(fp)()) std::__1::__invoke<void () block_pointer __strong&>(&&, decltype(std::__1::forward<void () block_pointer __strong&>(fp)())&&...) at /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/type_traits:4339
#3	0x000000010032abad in void std::__1::__invoke_void_return_wrapper<void>::__call<void () block_pointer __strong&>(void () block_pointer __strong&) at /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/__functional_base:349
#4	0x0000000100329901 in std::__1::__function::__func<void () block_pointer __strong, std::__1::allocator<std::__1::allocator>, void ()>::operator()() at /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/functional:1562
#5	0x000000010037b525 in std::__1::function<void ()>::operator()() const at /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/functional:1913
#6	0x000000010037b248 in facebook::react::tryAndReturnError(std::__1::function<void ()> const&) at src/react-native/React/CxxModule/RCTCxxUtils.mm:72
#7	0x0000000100314590 in ::-[RCTCxxBridge _tryAndHandleError:](dispatch_block_t) at src/react-native/React/CxxBridge/RCTCxxBridge.mm:264
#8	0x00000001003237a8 in ::-[RCTCxxBridge executeApplicationScript:url:async:](NSData *, NSURL *, BOOL) at rc/react-native/React/CxxBridge/RCTCxxBridge.mm:1300
#9	0x000000010032314c in ::-[RCTCxxBridge enqueueApplicationScript:url:onComplete:](NSData *, NSURL *, dispatch_block_t) at /src/react-native/React/CxxBridge/RCTCxxBridge.mm:1280
#10	0x000000010031dddc in ::-[RCTCxxBridge executeSourceCode:sync:](NSData *, BOOL) at /src/react-native/React/CxxBridge/RCTCxxBridge.mm:904
#11	0x000000010031658f in ::__21-[RCTCxxBridge start]_block_invoke.191() at /src/react-native/React/CxxBridge/RCTCxxBridge.mm:380
#12	0x0000000102fb4e7c in _dispatch_call_block_and_release ()
#13	0x0000000102fb5f1b in _dispatch_client_callout ()
#14	0x0000000102fc8a06 in _dispatch_root_queue_drain ()
#15	0x0000000102fc92da in _dispatch_worker_thread2 ()
#16	0x000000010302f0b7 in _pthread_wqthread ()
#17	0x000000010302ee01 in start_wqthread ()
Enqueued from com.apple.main-thread (Thread 1) Queue : com.apple.main-thread (serial)
#0	0x0000000102fb71d9 in _dispatch_group_wake ()
#1	0x0000000102fc45af in _dispatch_main_queue_callback_4CF ()
#2	0x00007fff2f1c0cd7 in __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ ()
#3	0x00007fff2f1c0401 in __CFRunLoopRun ()
#4	0x00007fff2f1bf8be in CFRunLoopRunSpecific ()
#5	0x00007fff2e4ab96b in RunCurrentEventLoopInMode ()
#6	0x00007fff2e4ab6a5 in ReceiveNextEventCommon ()
#7	0x00007fff2e4ab436 in _BlockUntilNextEventMatchingListInModeWithFilter ()
#8	0x00007fff2c845987 in _DPSNextEvent ()
#9	0x00007fff2c84471f in -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] ()
#10	0x00007fff2c83e83c in -[NSApplication run] ()
#11	0x00007fff2c82dd7c in NSApplicationMain ()
#12	0x0000000100103c3d in main at /Users/######
#13	0x00007fff5b0ee3d5 in start ()

@hramos hramos added the p: Microsoft Partner: Microsoft label Aug 9, 2019
@react-native-bot react-native-bot added the No CLA Authors need to sign the CLA before a PR can be reviewed. label Aug 10, 2019
@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Aug 12, 2019
@facebook-github-bot
Copy link
Contributor

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks!

@react-native-bot react-native-bot removed the No CLA Authors need to sign the CLA before a PR can be reviewed. label Aug 12, 2019
@basisworldwide
Copy link

Will this change be merged in anytime soon? It resolves the timing crash for me on app start.

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hramos has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@react-native-bot
Copy link
Collaborator

This pull request was successfully merged by @ahimberg in 0c2db32.

When will my fix make it into a release? | Upcoming Releases

@react-native-bot react-native-bot added the Merged This PR has been merged. label Mar 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged This PR has been merged. p: Microsoft Partner: Microsoft Platform: iOS iOS applications.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants