-
Notifications
You must be signed in to change notification settings - Fork 24.9k
Description
- I have reviewed the documentation
- I have searched existing issues
- I am using the latest React Native version
The app intermittently crashes when resolving or rejecting a promise in a native module. Possibly related to #5011.
This reproduces with several native modules so I don't think it's related to a specific module.
Environment
Environment:
OS: macOS High Sierra 10.13.3
Node: 9.5.0
Yarn: 1.3.2
npm: 5.6.0
Watchman: 4.9.0
Xcode: Xcode 9.2 Build version 9C40b
Android Studio: 3.0 AI-171.4443003
Packages: (wanted => installed)
react: ^16.3.0-alpha.1 => 16.3.0-alpha.3
react-native: 0.55.0 => 0.55.0
Steps to Reproduce
- Create a simple Native Module
- Use it
Expected Behavior
I expect the data to flow back and forth as documented.
Actual Behavior
The app intermittently crashes with what looks like a memory issue.
From my observation I think it happens when resolving or rejecting a promise from Objective-C.
Here's a screenshot from the crash organizer. Note that the crash occurred on thread 10, not the main thread:
So it looks like it's somewhere in this code:
react-native/React/CxxModule/RCTNativeModule.mm
Lines 86 to 115 in 26684cf
static MethodCallResult invokeInner(RCTBridge *bridge, RCTModuleData *moduleData, unsigned int methodId, const folly::dynamic ¶ms) { | |
if (!bridge || !bridge.valid || !moduleData) { | |
return folly::none; | |
} | |
id<RCTBridgeMethod> method = moduleData.methods[methodId]; | |
if (RCT_DEBUG && !method) { | |
RCTLogError(@"Unknown methodID: %ud for module: %@", | |
methodId, moduleData.name); | |
} | |
NSArray *objcParams = convertFollyDynamicToId(params); | |
@try { | |
id result = [method invokeWithBridge:bridge module:moduleData.instance arguments:objcParams]; | |
return convertIdToFollyDynamic(result); | |
} | |
@catch (NSException *exception) { | |
// Pass on JS exceptions | |
if ([exception.name hasPrefix:RCTFatalExceptionName]) { | |
@throw exception; | |
} | |
NSString *message = [NSString stringWithFormat: | |
@"Exception '%@' was thrown while invoking %s on target %@ with params %@\ncallstack: %@", | |
exception, method.JSMethodName, moduleData.name, objcParams, exception.callStackSymbols]; | |
RCTFatal(RCTErrorWithMessage(message)); | |
} | |
return folly::none; | |
} |
I see that code can throw this exception:
Exception '%@' was thrown while invoking %s on target %@ with params %@\ncallstack: %@",
exception
But I don't see that error anywhere in the crash log so I'm not sure where to find it. I'm not sure if this was the actual exception, since the crash report says EXC_CORPSE_NOTIFY
so it may be a red herring