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

Calling Sentry.setUser(null) on React Native v0.77.1 causes a crash on iOS in production / release mode #4553

Closed
hrastnik opened this issue Feb 17, 2025 · 5 comments · Fixed by #4567

Comments

@hrastnik
Copy link

hrastnik commented Feb 17, 2025

@sentry/react-native SDK Version

6.7.0

How does your development environment look like?

System:
  OS: macOS 15.3
  CPU: (12) arm64 Apple M2 Pro
  Memory: 195.33 MB / 16.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 22.13.1
    path: ~/.nvm/versions/node/v22.13.1/bin/node
  Yarn:
    version: 1.22.22
    path: ~/.nvm/versions/node/v22.13.1/bin/yarn
  npm:
    version: 11.1.0
    path: ~/.nvm/versions/node/v22.13.1/bin/npm
  Watchman:
    version: 2024.12.02.00
    path: /opt/homebrew/bin/watchman
Managers:
  CocoaPods:
    version: 1.16.2
    path: /var/folders/ht/h1xcpc3x137gqf6d8dn3z9l40000gn/T/frum_74676_1739784191370/bin/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 24.2
      - iOS 18.2
      - macOS 15.2
      - tvOS 18.2
      - visionOS 2.2
      - watchOS 11.2
  Android SDK: Not Found
IDEs:
  Android Studio: 2024.2 AI-242.23339.11.2421.12483815
  Xcode:
    version: 16.2/16C5032a
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 17.0.9
    path: /usr/bin/javac
  Ruby:
    version: 2.7.6
    path: /var/folders/ht/h1xcpc3x137gqf6d8dn3z9l40000gn/T/frum_74676_1739784191370/bin/ruby
npmPackages:
  "@react-native-community/cli":
    installed: 15.1.3
    wanted: 15.1.3
  react:
    installed: 18.3.1
    wanted: 18.3.1
  react-native:
    installed: 0.77.1
    wanted: 0.77.1
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: true
iOS:
  hermesEnabled: true
  newArchEnabled: true

Sentry.init()


Sentry.init({
  dsn: 'https://<redacted>.sentry.io/',
});

Steps to Reproduce

  1. Create a new RN project with react-native init
  2. Run npx @sentry/wizard@latest -i reactNative
  3. Build the app in production / release mode for iOS
  4. Call Sentry.setUser(null)

This is the code which is enough to reproduce the issue:

import React from 'react';
import {Alert, Button, View} from 'react-native';

import * as Sentry from '@sentry/react-native';

Sentry.init({
  dsn: 'https://<redacted>.sentry.io/',

  // uncomment the line below to enable Spotlight (https://spotlightjs.com)
  // spotlight: __DEV__,
});

export default function App() {
  return (
    <View style={{padding: 64, flex: 1, backgroundColor: 'white'}}>
      <Button
        title="Sentry.setUser(null)"
        onPress={() => {
          Sentry.setUser(null);
          Alert.alert('User has been set to null');
        }}
      />
    </View>
  );
}

Result

App crashes with error:

libc++abi: terminating due to uncaught exception of type facebook::jsi::JSError: Exception in HostFunction: -[NSNull objectForKeyedSubscript:]: unrecognized selector sent to instance 0x1e3a77a80
@krystofwoldrich
Copy link
Member

Hi @hrastnik,
thank you for the message,

sadly we are not able to reproduce the crash by calling Sentry.setUser(null);.

Could you share with us the whole stack trace of the crash?

@krystofwoldrich krystofwoldrich moved this from Needs Discussion to Needs More Information in Mobile & Cross Platform SDK Feb 17, 2025
@getsantry getsantry bot moved this to Waiting for: Community in GitHub Issues with 👀 3 Feb 17, 2025
@radko93
Copy link

radko93 commented Feb 17, 2025

I'm having the same issue on React Native 0.77.1 new arch static linking. I'm calling it in a cleanup of a useEffect. It only crashes in release mode.
None of the stack traces are really helpful.

EXC_BAD_ACCESS:  p@L_ >
Attempted to dereference null pointer.
xxx`main:
    0x104e9b0f0 <+0>:   stp    x24, x23, [sp, #-0x40]!
    0x104e9b0f4 <+4>:   stp    x22, x21, [sp, #0x10]
    0x104e9b0f8 <+8>:   stp    x20, x19, [sp, #0x20]
    0x104e9b0fc <+12>:  stp    x29, x30, [sp, #0x30]
    0x104e9b100 <+16>:  add    x29, sp, #0x30
    0x104e9b104 <+20>:  bl     0x104e9ab58               ; type metadata accessor for xxx.AppDelegate at <compiler-generated>
    0x104e9b108 <+24>:  mov    x19, x0
    0x104e9b10c <+28>:  bl     0x105b7cfe8               ; symbol stub for: static Swift.CommandLine.unsafeArgv.getter : Swift.UnsafeMutablePointer<Swift.Optional<Swift.UnsafeMutablePointer<Swift.Int8>>>
    0x104e9b110 <+32>:  mov    x20, x0
    0x104e9b114 <+36>:  bl     0x105b7cff4               ; symbol stub for: static Swift.CommandLine.argc.getter : Swift.Int32
    0x104e9b118 <+40>:  bl     0x105b7cff4               ; symbol stub for: static Swift.CommandLine.argc.getter : Swift.Int32
    0x104e9b11c <+44>:  mov    x21, x0
    0x104e9b120 <+48>:  mov    x0, x19
    0x104e9b124 <+52>:  bl     0x105b803c0               ; symbol stub for: swift_getObjCClassFromMetadata
    0x104e9b128 <+56>:  bl     0x105b7e5d8               ; symbol stub for: NSStringFromClass
    0x104e9b12c <+60>:  mov    x29, x29
    0x104e9b130 <+64>:  bl     0x105b7fa6c               ; symbol stub for: objc_retainAutoreleasedReturnValue
    0x104e9b134 <+68>:  mov    x19, x0
    0x104e9b138 <+72>:  bl     0x105b7c2ec               ; symbol stub for: static Swift.String._unconditionallyBridgeFromObjectiveC(Swift.Optional<__C.NSString>) -> Swift.String
    0x104e9b13c <+76>:  mov    x22, x0
    0x104e9b140 <+80>:  mov    x23, x1
    0x104e9b144 <+84>:  mov    x0, x19
    0x104e9b148 <+88>:  bl     0x105b7fa3c               ; symbol stub for: objc_release
    0x104e9b14c <+92>:  mov    x0, x21
    0x104e9b150 <+96>:  mov    x1, x20
    0x104e9b154 <+100>: mov    x2, #0x0                  ; =0 
    0x104e9b158 <+104>: mov    x3, #0x0                  ; =0 
    0x104e9b15c <+108>: mov    x4, x22
    0x104e9b160 <+112>: mov    x5, x23
    0x104e9b164 <+116>: bl     0x105b7a51c               ; symbol stub for: UIKit.UIApplicationMain(Swift.Int32, Swift.Optional<Swift.UnsafeMutablePointer<Swift.UnsafeMutablePointer<Swift.Int8>>>, Swift.Optional<Swift.String>, Swift.Optional<Swift.String>) -> Swift.Int32
->  0x104e9b168 <+120>: mov    x19, x0
    0x104e9b16c <+124>: mov    x0, x23
    0x104e9b170 <+128>: bl     0x105b801c8               ; symbol stub for: swift_bridgeObjectRelease
    0x104e9b174 <+132>: mov    x0, x19
    0x104e9b178 <+136>: bl     0x105b7f544               ; symbol stub for: exit

@getsantry getsantry bot moved this from Waiting for: Community to Waiting for: Product Owner in GitHub Issues with 👀 3 Feb 17, 2025
@hrastnik
Copy link
Author

@krystofwoldrich The crash only happens in production, in iOS release builds. I can try to isolate a repro case later today.

@kahest kahest moved this from Needs More Information to Needs Investigation in Mobile & Cross Platform SDK Feb 17, 2025
@hrastnik hrastnik changed the title Calling Sentry.setUser(null) causes a crash on iOS Calling Sentry.setUser(null) on React Native v0.77.1 causes a crash on iOS in production / release mode Feb 17, 2025
@krystofwoldrich
Copy link
Member

@hrastnik and @radko93 Thank you for the details, I'll try to reproduce it again in Release.

@krystofwoldrich
Copy link
Member

krystofwoldrich commented Feb 19, 2025

I reproduced the crash, and we are investigating it now.

Update:

The issue is in null not being transformed to nil as it does in Debug and older RN versions.

I suspect this change in RN causing it. facebook/react-native#49250

My comment about the unexpected behavior facebook/react-native#49250 (comment)

@krystofwoldrich krystofwoldrich self-assigned this Feb 19, 2025
@krystofwoldrich krystofwoldrich moved this from Needs Investigation to In Investigation in Mobile & Cross Platform SDK Feb 19, 2025
@krystofwoldrich krystofwoldrich moved this from In Investigation to In Progress in Mobile & Cross Platform SDK Feb 19, 2025
@github-project-automation github-project-automation bot moved this from In Progress to Done in Mobile & Cross Platform SDK Feb 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Status: Done
Development

Successfully merging a pull request may close this issue.

3 participants