dd-sdk-reactnative icon indicating copy to clipboard operation
dd-sdk-reactnative copied to clipboard

NSInternalInconsistencyException causing app crash

Open wongk opened this issue 7 months ago • 9 comments

Describe the bug

Our app has been crashing regularly on iOS due to an uncaught exception from the Datadog SDK.

Reproduction steps

No particular actions necessary. After the app has been open for a while it will eventually crash with this error.

SDK logs

[CoreFoundation] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Error when sending event: RumSessionStarted with body: {
isDiscarded = 0;
sessionId = "AE8BA47C-8AF3-47B3-9BD9-108B46BF6780";
}. RCTCallableJSModules is not set. This is probably because you've explicitly synthesized the RCTCallableJSModules in DdSdk, even though it's inherited from
RCTEventEmitter.'
*** First throw call stack:
(
0   CoreFoundation                      0x00000001804ae0f8 __exceptionPreprocess + 172
1   libobjc.A.dylib                     0x0000000180087db4 objc_exception_throw + 56
2   Foundation                          0x0000000180d1718c -[NSMutableDictionary(NSMutableDictionary) classForCoder] + 0
3   Healthy.debug.dylib                 0x000000010db33950 -[RCTEventEmitter sendEventWithName:body:] + 372
4   Healthy.debug.dylib                 0x000000010cf6d154
$s21DatadogSDKReactNative05DdSdkC14InitializationC21buildRUMConfiguration13configuration12eventEmitter0A3RUM0L0O13Confi<…>

Expected behavior

No response

Affected SDK versions

2.6.6

Latest working SDK version

unknown

Did you confirm if the latest SDK version fixes the bug?

Yes

Integration Methods

Yarn

React Native Version

0.77.1

Package.json Contents

No response

iOS Setup

No response

Android Setup

No response

Device Information

iOS simulator

Other relevant information

No response

wongk avatar Apr 18 '25 14:04 wongk

Hi @wongk, thanks for reaching out 👋

Could you please share a few more details such as your package.json and SDK initialization setup code? Are you using the New or Old architecture?

Thanks!

sbarrio avatar Apr 21 '25 16:04 sbarrio

I have actually been going back and forth between new arch on and off, but I know for sure I have seen this issue with it off.

package.json

{
  "name": "expo-app",
  "version": "1.0.0",
  "main": "index.js",
  "private": true,
  "scripts": {
    ...
  },
  "dependencies": {
    "@datadog/mobile-react-native": "^2.6.6",
    "@expo/config-plugins": "~9.0.9",
    "@fortawesome/react-native-fontawesome": "^0.3.2",
    "@launchdarkly/react-native-client-sdk": "^10.9.9",
    "@my/api": "0.0.1",
    "@my/config": "0.0.1",
    "@my/ui": "0.0.1",
    "@my/utils": "0.0.1",
    "@react-native-async-storage/async-storage": "^2.0.0",
    "@react-native-clipboard/clipboard": "^1.16.0",
    "@react-native-community/netinfo": "^11.3.3",
    "@react-native-menu/menu": "^1.2.2",
    "@react-native-picker/picker": "^2.11.0",
    "@react-navigation/elements": "^2.2.5",
    "@react-navigation/native": "^7.0.14",
    "@shopify/react-native-skia": "^1.11.18",
    "@tamagui/linear-gradient": "^1.125.26",
    "@tamagui/portal": "^1.125.26",
    "@tanstack/react-query": "5.64.1",
    "app": "0.1.0",
    "burnt": "^0.12.2",
    "expo": "~52.0.46",
    "expo-application": "~6.0.2",
    "expo-build-properties": "~0.13.2",
    "expo-constants": "~17.0.8",
    "expo-datadog": "^52.0.1",
    "expo-dev-client": "~5.0.20",
    "expo-dev-menu": "6.0.23",
    "expo-device": "~7.0.3",
    "expo-file-system": "~18.0.12",
    "expo-font": "~13.0.4",
    "expo-linear-gradient": "~14.0.2",
    "expo-linking": "~7.0.5",
    "expo-localization": "~16.0.1",
    "expo-notifications": "~0.29.14",
    "expo-router": "~4.0.20",
    "expo-splash-screen": "~0.29.24",
    "expo-status-bar": "~2.0.1",
    "expo-system-ui": "~4.0.9",
    "expo-updates": "~0.27.3",
    "mixpanel-react-native": "^3.0.8",
    "posthog-react-native": "^3.11.2",
    "react": "18.3.1",
    "react-dom": "^18.3.1",
    "react-native": "^0.77.0",
    "react-native-auth0": "^4.4.0",
    "react-native-fast-image": "git+https://github.com/wongk/react-native-fast-image.git#v8.9.3",
    "react-native-gesture-handler": "^2.22.0",
    "react-native-ios-context-menu": "^2.5.2",
    "react-native-ios-utilities": "^4.5.3",
    "react-native-keyboard-controller": "^1.16.7",
    "react-native-mmkv": "^2.12.2",
    "react-native-reanimated": "^3.16.7",
    "react-native-safe-area-context": "^5.1.0",
    "react-native-screens": "^4.5.0",
    "react-native-svg": "^15.11.1",
    "react-native-web": "^0.19.13",
    "tamagui": "^1.125.26",
    "use-effect-event": "^1.0.2",
    "victory-native": "37.3.2"
  },
  "devDependencies": {
    "@babel/core": "^7.26.0",
    "@datadog/datadog-ci": "^3.1.0",
    "@expo/metro-config": "~0.19.4",
    "@tamagui/babel-plugin": "^1.125.26",
    "babel-plugin-module-resolver": "^5.0.2",
    "metro-minify-terser": "^0.81.0",
    "react-native-clean-project": "^4.0.3",
    "typescript": "~5.6.3"
  },
  "expo": {
    "install": {
      "exclude": [
        "react-native@~0.76.6",
        "react-native-reanimated@~3.16.1",
        "react-native-gesture-handler@~2.20.0",
        "react-native-screens@~4.4.0",
        "react-native-safe-area-context@~4.12.0",
        "[email protected]",
        "react-native-webview@~13.12.5",
        "@react-native-async-storage/[email protected]",
        "@react-native-picker/[email protected]",
        "@shopify/[email protected]"
      ]
    }
  }
}

SDK init

import { User } from "@my/api"
import { Environment } from "@my/config/src/environment"
import { nativeApplicationVersion } from "expo-application"
import {
  DdSdkReactNative,
  DdSdkReactNativeConfiguration,
  SdkVerbosity,
  TrackingConsent,
} from "expo-datadog"

let initialized = false

export async function initDatadogRUM() {
  if (initialized) return
  initialized = true

  const config = new DdSdkReactNativeConfiguration(
    Environment.DATADOG_CLIENT_TOKEN,
    Environment.ENV,
    Environment.DATADOG_APP_ID,
    true, // track user interactions (such as a tap on buttons)
    true, // track XHR resources
    Environment.ENV !== "", // track errors if the environment is defined
    TrackingConsent.GRANTED,
  )

  config.site = "US1"
  config.nativeCrashReportEnabled = true
  config.sessionSamplingRate = 100
  config.resourceTracingSamplingRate = 20
  config.firstPartyHosts = [Environment.SERVER_HOST]
  config.verbosity = SdkVerbosity.WARN

  await DdSdkReactNative.initialize(config)
  await DdSdkReactNative.setAttributes({
    buildNumber: nativeApplicationVersion,
  })
}

export async function setDatadogUser(user: User) {
  return await DdSdkReactNative.setUser({
    id: user.auth0Id,
  })
}

wongk avatar Apr 21 '25 17:04 wongk

We are getting the same issue after a reload. Looks like a reference to an old EventEmitter is retained when the JS is reloaded.

rorycaseyap avatar Apr 23 '25 08:04 rorycaseyap

I can confirm I'm seeing this issue with the new architecture enabled in React Native 0.78.2 in dev mode. I haven't yet attempted to reproduce it with a production build to know whether this is dev mode specific or not, but it's entirely possible based on the error.

I note that this PR landed recently which re-writes the core of the event emitter and may be related: https://github.com/DataDog/dd-sdk-reactnative/pull/839/files

chrisbianca avatar Apr 23 '25 13:04 chrisbianca

@rorycaseyap @chrisbianca Thanks for the extra context!

@wongk @rorycaseyap Are you seeing this also on release builds or just in debug mode?

sbarrio avatar Apr 24 '25 07:04 sbarrio

i only see this in dev mode as far as i know, no report from production

EDIT: as mentioned in the comment under, the crash coming from datadog, doesn't make me confident either that it doesn't happen in release or not since i wouldn't know depending on datadog for production logs.

wcastand avatar Apr 24 '25 09:04 wcastand

I don't run release builds, and given that the crash is in DataDog itself, I am not confident that a lack of crash reports means it's not crashing in production.

wongk avatar Apr 24 '25 14:04 wongk

I'm getting this error when I go offline and try to report some error to DataDog using DdLogs.error

vargajacint avatar Apr 25 '25 13:04 vargajacint

With further investigation, I was able to identify the reproduction:

DdLogs.error("error message", { "profiled": 123} ); // If I pass an object to second argument it brakes
DdLogs.error("error message" ); // This works

Edit: It seems the issue for me was the context object values type. If it's a Number, it breaks. String works well

vargajacint avatar Apr 25 '25 19:04 vargajacint

@sbarrio so far we have only seen this in debug mode

rorycaseyap avatar Apr 29 '25 22:04 rorycaseyap

Thank you for reporting the issue, this does indeed affect dev, and we were able to reproduce it on our side. The fix for this will be included on the next release.

cdn34dd avatar Apr 30 '25 15:04 cdn34dd

Hi, I'm facing the same issue, but I'm not using the new architecture with Expo 52.

app.config.ts

{
  newArchEnabled: false,
}

@cdn34dd Just to clarify — will the fix be included in version 2.7.0, or in a later release? Thanks!

Here is the following error:

-------------------------------------
Translated Report (Full Report Below)
-------------------------------------

Incident Identifier: B85D3F6F-C27A-41C0-8575-24F57EC77212
CrashReporter Key: 1DB6DA81-5625-582C-9AFF-D24B92BF9078
Hardware Model: Mac15,6
Process: MyExpoApp [46803]
Path: /Users/USER/Library/Developer/CoreSimulator/Devices/4D29A88B-3EDC-475A-8800-0D0C58879D10/data/Containers/Bundle/Application/BD79B25F-78D0-4182-A70D-D2BB6441B2C0/MyExpoApp.app/MyExpoApp
Identifier: fr.myexpoapp
Version: 3.7.6 (268)
Code Type: ARM-64 (Native)
Role: Foreground
Parent Process: launchd_sim [96850]
Coalition: com.apple.CoreSimulator.SimDevice.4D29A88B-3EDC-475A-8800-0D0C58879D10 [81423]
Responsible Process: SimulatorTrampoline [1094]

Date/Time: 2025-05-05 16:42:50.5805 +0200
Launch Time: 2025-05-05 14:27:25.0742 +0200
OS Version: macOS 15.3.1 (24D70)
Release Type: User
Report Version: 104

Exception Type:  EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Triggered by Thread:  10

Last Exception Backtrace:
0   CoreFoundation                	       0x1804b7570 __exceptionPreprocess + 160
1   libobjc.A.dylib               	       0x18008eda8 objc_exception_throw + 72
2   Foundation                    	       0x180e7a398 -[NSMutableDictionary(NSMutableDictionary) classForCoder] + 0
3   MyExpoApp.debug.dylib         	       0x10be88f5c -[RCTEventEmitter sendEventWithName:body:] + 372 (RCTEventEmitter.m:45)
4   MyExpoApp.debug.dylib         	       0x10b79e6ac closure #1 in DdSdkNativeInitialization.buildRUMConfiguration(configuration:eventEmitter:) + 532 (DdSdkNativeInitialization.swift:155)
5   MyExpoApp.debug.dylib         	       0x10b4f27a0 RUMApplicationScope.sessionScopeDidUpdate(_:) + 444 (RUMApplicationScope.swift:232)
6   MyExpoApp.debug.dylib         	       0x10b4f1c18 RUMApplicationScope.refresh(expiredSession:on:context:writer:) + 1584 (RUMApplicationScope.swift:191)
7   MyExpoApp.debug.dylib         	       0x10b4f09f0 closure #2 in RUMApplicationScope.process(command:context:writer:) + 628 (RUMApplicationScope.swift:121)
8   MyExpoApp.debug.dylib         	       0x10b4f0a64 partial apply for closure #2 in RUMApplicationScope.process(command:context:writer:) + 36
9   libswiftCore.dylib            	       0x1949dbfa4 Sequence.compactMap<A>(_:) + 668
10  libswiftCore.dylib            	       0x19495bec0 Sequence.compactMap<A>(_:) + 12
11  MyExpoApp.debug.dylib         	       0x10b4f0398 RUMApplicationScope.process(command:context:writer:) + 2116 (RUMApplicationScope.swift:96)
12  MyExpoApp.debug.dylib         	       0x10b4de4d8 closure #1 in Monitor.process(command:) + 320 (Monitor.swift:133)
13  MyExpoApp.debug.dylib         	       0x10b2c13ac closure #1 in CoreFeatureScope.eventWriteContext(bypassConsent:_:) + 180 (DatadogCore.swift:361)
14  MyExpoApp.debug.dylib         	       0x10b2c156c closure #1 in CoreFeatureScope.context(_:) + 80 (DatadogCore.swift:369)
15  MyExpoApp.debug.dylib         	       0x10b2ba724 closure #1 in DatadogContextProvider.read(block:) + 200 (DatadogContextProvider.swift:92)
16  MyExpoApp.debug.dylib         	       0x10b2a0728 thunk for @escaping @callee_guaranteed @Sendable () -> () + 48
17  libdispatch.dylib             	       0x1801774ec _dispatch_call_block_and_release + 24
18  libdispatch.dylib             	       0x180178de0 _dispatch_client_callout + 16
19  libdispatch.dylib             	       0x180180f60 _dispatch_lane_serial_drain + 956
20  libdispatch.dylib             	       0x180181a98 _dispatch_lane_invoke + 388
21  libdispatch.dylib             	       0x18018cf44 _dispatch_root_queue_drain_deferred_wlh + 276
22  libdispatch.dylib             	       0x18018c5a0 _dispatch_workloop_worker_thread + 440
23  libsystem_pthread.dylib       	       0x104c03b74 _pthread_wqthread + 284
24  libsystem_pthread.dylib       	       0x104c02934 start_wqthread + 8

Steffi3rd avatar May 06 '25 14:05 Steffi3rd

@Steffi3rd Sorry for the delay. The fix has been merged to develop and as such will be part of the next release, which should take place very soon.

@vargajacint Do you still have issues with DDLogs.error payload? We have not been able to reproduce it on our end, not with different payloads nor with connectivity changes taking place. That issue however appears to be separate from this one, so, if the problems persists, could you please open up a new issue sharing more info and even a sample app if possible? We don't want to lose track of it once we close this issue with the next release.

Thanks everyone for your support and patience 🙇

sbarrio avatar May 12 '25 09:05 sbarrio

Hi. We have just released v2.7.1 which includes a fix for this issue. As such, we are going to close the issue, but please feel free to open a new one in case the problem persists.

Thank you all for your patience.

sbarrio avatar May 14 '25 15:05 sbarrio

Thank you guys! We are trying that now 🙏 @sbarrio

Steffi3rd avatar May 21 '25 14:05 Steffi3rd