🔥 App crashes on receiving a notification in the background
Issue
When my app is in background and when I receive push notification and when I click it or click app icon my app crashes with error:
2020-04-20 12:12:43.334503+0200 mobile[450:58454] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'this request has been neutered - you can't call -sendResponse: twice nor after encoding it'
in Crashlytics I see:
Fatal Exception: NSInternalInconsistencyException
0 CoreFoundation 0x1aabf7ab0 __exceptionPreprocess
1 libobjc.A.dylib 0x1aa911028 objc_exception_throw
2 CoreFoundation 0x1aaaf46ac +[_CFXNotificationTokenRegistration keyCallbacks]
3 Foundation 0x1aaf35720 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:]
4 BaseBoard 0x1ad7e8334 __40-[BSAction sendResponse:withCompletion:]_block_invoke
5 libdispatch.dylib 0x1aa89dfd8 _dispatch_client_callout
6 libdispatch.dylib 0x1aa8aa7f4 _dispatch_lane_barrier_sync_invoke_and_complete
7 BaseBoard 0x1ad7992e0 -[BSAction sendResponse:withCompletion:]
8 UIKitCore 0x1ae847374 -[UIHandleRemoteNotificationAction sendResponse:]
9 UIKitCore 0x1aecf3830 __91-[UIApplication _handleNonLaunchSpecificActions:forScene:withTransitionContext:completion:]_block_invoke_3.2753
10 UIKitCore 0x1aecf4094 __130-[UIApplication _updateStateRestorationArchiveForBackgroundEvent:saveState:exitIfCouldNotRestoreState:updateSnapshot:windowScene:]_block_invoke
11 UIKitCore 0x1aece71e0 _runAfterCACommitDeferredBlocks
12 UIKitCore 0x1aecd6658 _cleanUpAfterCAFlushAndRunDeferredBlocks
13 UIKitCore 0x1aed07b14 _afterCACommitHandler
14 CoreFoundation 0x1aab72668 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__
15 CoreFoundation 0x1aab6d308 __CFRunLoopDoObservers
16 CoreFoundation 0x1aab6d8b8 __CFRunLoopRun
17 CoreFoundation 0x1aab6d084 CFRunLoopRunSpecific
18 GraphicsServices 0x1b4dbb534 GSEventRunModal
19 UIKitCore 0x1aecdd698 UIApplicationMain
20 mobile 0x104022314 main + 13 (main.m:13)
21 libdyld.dylib 0x1aa9ece18 start
my app crashes even with empty method
- (void) application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)notification fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
but when I remove didReceiveRemoteNotification from my AppDelegate.m no crash not occurs
After some investigation I also found that commenting one line in GULAppDelegateSwizzler.m helps
// Notify interceptors.
[GULAppDelegateSwizzler
notifyInterceptorsWithMethodSelector:methodSelector
callback:^(id<GULApplicationDelegate> interceptor) {
NSInvocation *invocation = [GULAppDelegateSwizzler
appDelegateInvocationForSelector:methodSelector];
[invocation setTarget:interceptor];
[invocation setSelector:methodSelector];
[invocation setArgument:(void *)(&application) atIndex:2];
[invocation setArgument:(void *)(&userInfo) atIndex:3];
this ----> //[invocation setArgument:(void *)(&completionHandler) atIndex:4];
[invocation invoke];
}];
And also disabling Swizzling helps too
Project Files
Javascript
Click To Expand
package.json:
"@react-native-firebase/analytics": "^6.4.0",
"@react-native-firebase/app": "^6.4.0",
"@react-native-firebase/auth": "^6.4.0",
"@react-native-firebase/crashlytics": "^6.4.0",
"@react-native-firebase/dynamic-links": "^6.4.0",
"@react-native-firebase/iid": "^6.4.0",
"@react-native-firebase/in-app-messaging": "^6.4.0",
"@react-native-firebase/messaging": "^6.4.0",
"@react-native-firebase/perf": "^6.4.0",
"@react-native-firebase/remote-config": "^6.4.0",```
#### `firebase.json` for react-native-firebase v6:
```json
# N/A
iOS
Click To Expand
ios/Podfile:
- [ ] I'm not using Pods
- [x] I'm using Pods and my Podfile looks like:
platform :ios, '10.0'
require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'
permissions_path = '../node_modules/react-native-permissions/ios'
target 'mobile' do
pod 'FBLazyVector', :path => "../node_modules/react-native/Libraries/FBLazyVector"
pod 'FBReactNativeSpec', :path => "../node_modules/react-native/Libraries/FBReactNativeSpec"
pod 'RCTRequired', :path => "../node_modules/react-native/Libraries/RCTRequired"
pod 'RCTTypeSafety', :path => "../node_modules/react-native/Libraries/TypeSafety"
pod 'React', :path => '../node_modules/react-native/'
pod 'React-Core', :path => '../node_modules/react-native/'
pod 'React-CoreModules', :path => '../node_modules/react-native/React/CoreModules'
pod 'React-Core/DevSupport', :path => '../node_modules/react-native/'
pod 'React-RCTActionSheet', :path => '../node_modules/react-native/Libraries/ActionSheetIOS'
pod 'React-ART', :path => '../node_modules/react-native/Libraries/ART'
pod 'React-RCTAnimation', :path => '../node_modules/react-native/Libraries/NativeAnimation'
pod 'React-RCTBlob', :path => '../node_modules/react-native/Libraries/Blob'
pod 'React-RCTImage', :path => '../node_modules/react-native/Libraries/Image'
pod 'React-RCTLinking', :path => '../node_modules/react-native/Libraries/LinkingIOS'
pod 'React-RCTNetwork', :path => '../node_modules/react-native/Libraries/Network'
pod 'React-RCTSettings', :path => '../node_modules/react-native/Libraries/Settings'
pod 'React-RCTText', :path => '../node_modules/react-native/Libraries/Text'
pod 'React-RCTVibration', :path => '../node_modules/react-native/Libraries/Vibration'
pod 'React-Core/RCTWebSocket', :path => '../node_modules/react-native/'
pod 'React-cxxreact', :path => '../node_modules/react-native/ReactCommon/cxxreact'
pod 'React-jsi', :path => '../node_modules/react-native/ReactCommon/jsi'
pod 'React-jsiexecutor', :path => '../node_modules/react-native/ReactCommon/jsiexecutor'
pod 'React-jsinspector', :path => '../node_modules/react-native/ReactCommon/jsinspector'
pod 'ReactCommon/jscallinvoker', :path => "../node_modules/react-native/ReactCommon"
pod 'ReactCommon/turbomodule/core', :path => "../node_modules/react-native/ReactCommon"
pod 'Yoga', :path => '../node_modules/react-native/ReactCommon/yoga'
pod 'DoubleConversion', :podspec => '../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec'
pod 'glog', :podspec => '../node_modules/react-native/third-party-podspecs/glog.podspec'
pod 'Folly', :podspec => '../node_modules/react-native/third-party-podspecs/Folly.podspec'
pod 'Permission-Calendars', :path => "#{permissions_path}/Calendars.podspec"
pod 'Permission-Camera', :path => "#{permissions_path}/Camera.podspec"
pod 'Permission-Contacts', :path => "#{permissions_path}/Contacts.podspec"
pod 'Permission-FaceID', :path => "#{permissions_path}/FaceID.podspec"
pod 'Permission-LocationAlways', :path => "#{permissions_path}/LocationAlways.podspec"
pod 'Permission-LocationWhenInUse', :path => "#{permissions_path}/LocationWhenInUse.podspec"
pod 'Permission-Notifications', :path => "#{permissions_path}/Notifications.podspec"
pod 'Permission-PhotoLibrary', :path => "#{permissions_path}/PhotoLibrary.podspec"
pod 'Permission-SpeechRecognition', :path => "#{permissions_path}/SpeechRecognition.podspec"
pod 'AppCenter/Distribute'
pod 'Appboy-iOS-SDK'
pod 'Bolts'
pod 'FBSDKCoreKit', '~> 5.0'
pod 'FBSDKShareKit', '~> 5.0'
pod 'FBSDKLoginKit', '~> 5.0'
pod 'AccountKit'
pod 'GoogleIDFASupport', '~> 3.14.0'
pod 'react-native-geolocation', path: '../node_modules/@react-native-community/geolocation'
pod 'Intercom'
use_native_modules!
pod 'react-native-intercom', :path => '../node_modules/react-native-intercom'
end
def append_user_header_search_path(target, path)
target.build_configurations.each do |config|
headers = config.build_settings['USER_HEADER_SEARCH_PATHS']
if not headers
config.build_settings["USER_HEADER_SEARCH_PATHS"] ||= "$(inherited) "
end
config.build_settings['USER_HEADER_SEARCH_PATHS'] << path
end
end
AppDelegate.m:
// N/A
Android
Click To Expand
Have you converted to AndroidX?
- [ ] my application is an AndroidX application?
- [ ] I am using
android/gradle.settingsjetifier=truefor Android compatibility? - [ ] I am using the NPM package
jetifierfor react-native compatibility?
android/build.gradle:
// N/A
android/app/build.gradle:
// N/A
android/settings.gradle:
// N/A
MainApplication.java:
// N/A
AndroidManifest.xml:
<!-- N/A -->
Environment
Click To Expand
react-native info output:
System:
OS: macOS 10.15.4
CPU: (12) x64 Intel(R) Core(TM) i7-8850H CPU @ 2.60GHz
Memory: 3.90 GB / 32.00 GB
Shell: 5.7.1 - /bin/zsh
Binaries:
Node: 10.16.0 - ~/.nvm/versions/node/v10.16.0/bin/node
Yarn: 1.21.1 - /usr/local/bin/yarn
npm: 6.9.0 - ~/.nvm/versions/node/v10.16.0/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
SDKs:
iOS SDK:
Platforms: iOS 13.4, DriverKit 19.0, macOS 10.15, tvOS 13.4, watchOS 6.2
Android SDK:
API Levels: 25, 27, 28
Build Tools: 23.0.1, 25.0.2, 25.0.3, 26.0.2, 27.0.1, 27.0.3, 28.0.0, 28.0.2, 28.0.3, 29.0.2
System Images: android-25 | Google APIs Intel x86 Atom, android-26 | Google APIs Intel x86 Atom, android-29 | Google APIs Intel x86 Atom
Android NDK: 16.1.4479499
IDEs:
Android Studio: 3.5 AI-191.8026.42.35.5977832
Xcode: 11.4/11E146 - /usr/bin/xcodebuild
npmPackages:
@react-native-community/cli: ^3.1.0 => 3.1.0
react: 16.9.0 => 16.9.0
react-native: 0.61.5 => 0.61.5
- Platform that you're experiencing the issue on:
- [ x] iOS
- [ ] Android
- [ ] iOS but have not tested behavior on Android
- [ ] Android but have not tested behavior on iOS
- [ ] Both
react-native-firebaseversion you're using that has this issue:6.3.0,6.4.0
Firebasemodule(s) you're using that has the issue:e.g. Instance ID
- Are you using
TypeScript?Y
- 👉 Check out
React Native FirebaseandInvertaseon Twitter for updates on the library.
Have you tried the @next tag to get the results of the massive messaging/notification cleanup in PR #3339 ? If not you should definitely try it
with 6.4.1-alpha.0 the same exception
I am also having the same issue with Android devices in production. I get this error on crashlytics:
Fatal Exception: com.facebook.react.common.JavascriptException
TypeError: undefined is not an object (evaluating 'u()(c).then'), stack: startHeadlessTask@340:2857 value@40:3685 <unknown>@40:841 value@40:2939 value@40:813 value@-1
com.facebook.react.modules.core.ExceptionsManagerModule.reportException
At the Logs section of crashlytics I can see that the only previous event is:
notification_receive
All devices are in Background mode
Could it be related to this?
I'm facing this problem too. Still finding solution to solve it.
I had the same issue on 6.4.0. I upgrade to 6.7.1 and still having the same issue.
@Oshianor the same issue? An iOS issue with stack and Android issue with error were printed here? Which one are you having? Perhaps open a new issue with full template details cross-linking to this or at least post logcat (Android) or Console/Xcode (iOS) crash trace information. "same issue" has very low value as troubleshooting information
Alright @mikehardy i'll do that.
Hello 👋, to help manage issues we automatically close stale issues. This issue has been automatically marked as stale because it has not had activity for quite some time. Has this issue been fixed, or does it still require the community's attention?
This issue will be closed in 15 days if no further activity occurs. Thank you for your contributions.
it still requires the community's attention
@perrosnk "the community" is us, it includes you - if it went stale that means you are currently the interested person. Have you tried tracing through it to see why it's crashing, and creating a PR to fix?
@mikehardy I wish I could
I am also having the same issue with Android devices in production. I get this error on crashlytics:
Fatal Exception: com.facebook.react.common.JavascriptException TypeError: undefined is not an object (evaluating 'u()(c).then'), stack: startHeadlessTask@340:2857 value@40:3685 <unknown>@40:841 value@40:2939 value@40:813 value@-1 com.facebook.react.modules.core.ExceptionsManagerModule.reportExceptionAt the Logs section of crashlytics I can see that the only previous event is:
notification_receiveAll devices are in Background mode
I got a similar error that was caused since my handler in setBackgroundMessageHandler wasn't returning anything.
Making my handler method async fixed it for me (you could also return a promise.)
messaging().setBackgroundMessageHandler(async (remoteMessage) => {
Hello 👋, to help manage issues we automatically close stale issues. This issue has been automatically marked as stale because it has not had activity for quite some time. Has this issue been fixed, or does it still require the community's attention?
This issue will be closed in 15 days if no further activity occurs. Thank you for your contributions.
Closing this issue after a prolonged period of inactivity. If this is still present in the latest release, please feel free to create a new issue with up-to-date information.
We also had an issue with the crash mentioned in OP ("request has been neutered") in our apps but it seemed to only occur sporadically. Eventually I found out that this seems to happen often when the app is coming into the foreground just as a fcm message is received (spamming putting the app in background and opening it again quickly seemed to trigger the crash).
In my AppDelegate.m I had implemented didReceiveRemoteNotification in order to be able to route certain notifications to another library. If the message does not belong to this other library I would just call completionHandler() and let RNFB have it.
I'm not comfortable with objective c and delegates and method swizzling and whatnot but my observation is RNFB already calls completionHandler(), I guess after calling the swizzled method. So in my case, not calling the completionHandler in my didReceiveRemoteNotification seemed to do the trick.
Not stale?
We keep receiving crashes even though we have messaging().setBackgroundMessageHandler(async (remoteMessage) => {.
Please open a new issue with full details, paying special attention to react-native-firebase versions and firebase-ios-sdk versions being the most current stable releases (achieved with a Podfile override for firebase-ios-sdk - documented on rnfirebase.io main page). Anything from Apr 20 is likely to be stale simply owing to underlying dependency updates.
@rosskhanas
Did you find a solution to it? I'm having the same issue