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

Crash in [RCTModuleMethod invokeWithBridge:module:arguments:] when using DISPATCH_QUEUE_CONCURRENT #5011

Closed
philikon opened this issue Dec 28, 2015 · 2 comments
Labels
Resolution: Locked This issue was locked by the bot.

Comments

@philikon
Copy link
Contributor

Consider an iOS native module definition:

#import "RCTBridgeModule.h"

@interface RCT_EXTERN_REMAP_MODULE(Foobar, Foobar, NSObject)
RCT_EXTERN_METHOD(getFoobars:(nonnull NSNumber *)howMany callback:(RCTResponseSenderBlock *)callback)
@end

and an accompanying Swift implementation:

@objc(Foobar)
public class Foobar : NSObject {

  static let QUEUE = dispatch_queue_create("com.foobar.foobar", DISPATCH_QUEUE_CONCURRENT)
  var methodQueue: dispatch_queue_t {
    return Foobar.QUEUE;
  }

  public func getFoobars(howMany: NSNumber, callback: RCTResponseSenderBlock) {
    ...
  }
}

This setup worked fine in React Native 0.15. But since the upgrade to React Native 0.17 (I leap-frogged 0.16), it crashes randomly in [RCTModuleMethod invokeWithBridge:module:arguments:] with EXC_BAD_ACCESS at https://github.com/facebook/react-native/blob/v0.17.0/React/Base/RCTModuleMethod.m#L470 in Thread 18 (com.foobar.foobar).

(lldb) po _invocation
<NSInvocation: 0x165c68b0>
return value: {v} void
target: {@} 0x1653fc90
selector: {:} getFoobars:callback:
argument 2: {@} 0x178bcd90
argument 3: {@?} 0x165f6ca0 (block)

(lldb) po index
3

So it's trying to release the callback argument, but failing -- likely because it's already been released.

Making the module's queue not a concurrent queue, but a serial one (DISPATCH_QUEUE_SERIAL or simply nil) seems to make the problem go away.

It seems reasonable to me if React required native modules to only use serial queues, though perhaps that should be documented then. Or perhaps the release mechanism introduced in 71da291 needs some tweaking so it can work with concurrent queues? cc @tadeuzagallo

@mkonicek
Copy link
Contributor

Hi there! This issue is being closed because it has been inactive for a while.

But don't worry, it will live on with ProductPains! Check out its new home: https://productpains.com/post/react-native/crash-in-rctmodulemethod-invokewithbridgemodulearguments-when-using-dispatchqueueconcurrent

ProductPains helps the community prioritize the most important issues thanks to its voting feature.
It is easy to use - just login with GitHub.

Also, if this issue is a bug, please consider sending a PR with a fix.
We're a small team and rely on the community for bug fixes of issues that don't affect fb apps.

@bfarrgaynor
Copy link

Running into this on RN 53

@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 20, 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

4 participants