sentry-react-native icon indicating copy to clipboard operation
sentry-react-native copied to clipboard

Expo RN app crashes on real android device after migrating to expo environment variables: (__kernel_rt_sigreturn SIGSEGV: Segfault)

Open amakarevich11 opened this issue 1 year ago β€’ 18 comments

I have the following issue:

I'm experiencing a critical issue where my Expo React Native app crashes almost immediately after launching on real Android devices. The app works perfectly fine on emulators (both iOS and Android). The crash started occurring after migrating from react-native-config to Expo's environment variables system. After removing sentry from the project crash was disappeared. When running the app with the environment variable EXPO_NO_DOTENV=1, it works without crashing.

Environment:

Expo SDK Version: 51.0.32 Sentry SDK: @sentry/react-native (5.33.0) React Native Version: 0.74.5 Platform: Android (Real Devices Only) Development OS: [e.g., macOS Ventura 13.5]

Error Messages:

Sentry reports the following error: __kernel_rt_sigreturn SIGSEGV: Segfault. Image

Configuration:

(@sentry/react-native)

Sentry.init({
  dsn: process.env.EXPO_PUBLIC_SENTRY_DNS,
  environment: process.env.NODE_ENV,
  tracesSampleRate: 1.0,
  _experiments: {
    profilesSampleRate: 1.0,
  },
});

(package.json)

"android:development": "NODE_ENV=development expo run:android --device",

Steps to Reproduce:

  1. Migrate from react-native-config to Expo's environment variables by prefixing variables with EXPO_PUBLIC_ and accessing them via process.env.EXPO_PUBLIC_*.
  2. Build and run the app on a real Android device using expo run:android.
  3. Observe that the app crashes almost immediately after launch.

amakarevich11 avatar Sep 27 '24 11:09 amakarevich11

Hey @amakarevich11 thanks for reporting - we'll investigate and follow up here. Quick question for clarification - what happens on a production build? And can you reproduce this with a clean project setup?

kahest avatar Sep 27 '24 12:09 kahest

Hey @amakarevich11 thanks for reporting - we'll investigate and follow up here. Quick question for clarification - what happens on a production build? And can you reproduce this with a clean project setup?

We don't create production builds yet. I will check it with clean project setup and let you know.

amakarevich11 avatar Sep 27 '24 12:09 amakarevich11

Hey @amakarevich11 thanks for reporting - we'll investigate and follow up here. Quick question for clarification - what happens on a production build? And can you reproduce this with a clean project setup?

We don't create production builds yet. I will check it with clean project setup and let you know.

It doesn't reproduce on clean expo project.

amakarevich11 avatar Sep 27 '24 12:09 amakarevich11

@amakarevich11 thanks for testing this so quickly - do you see anything particular that's different in the setup/config from your actual RN Expo app? It would be great if you'd manage to repro the crash on the clean project.

kahest avatar Sep 27 '24 13:09 kahest

@amakarevich11 thanks for testing this so quickly - do you see anything particular that's different in the setup/config from your actual RN Expo app? It would be great if you'd manage to repro the crash on the clean project.

@kahest I don't see anything unusual in our actual expo app configuration, we created our project about 1 month ago, so it is pretty fresh and don't have a lot of configuration compare to clean project. But we migrate code base from bare react native project and add a lot of third party dependencies, maybe it can affect it someway. We noticed that it start to crash after migrating react native config to expo variables, before this commit it works ok with configured sentry.

amakarevich11 avatar Sep 27 '24 13:09 amakarevich11

Thank you for the prompt response @amakarevich11 πŸ™‡ Just an update on our side that we haven't been able to reproduce the issue yet.

We noticed that it start to crash after migrating react native config to expo variables, before this commit it works ok with configured sentry.

Could you provide more details on the applied changes that trigger the crash and a diff if possible?

antonis avatar Oct 01 '24 12:10 antonis

Tried with a newly created react-native app version 0.72.0 and fails.

xgenem avatar Oct 06 '24 04:10 xgenem

Tried with a newly created react-native app version 0.72.0 and fails.

Hey @xgenem πŸ‘‹ Could you provide more information on you setup. Which version of the Sentry SDK are you using? Does the crash happen only on real Android devices too?

antonis avatar Oct 07 '24 07:10 antonis

Tried with a newly created react-native app version 0.72.0 and fails.

Hey @xgenem πŸ‘‹ Could you provide more information on you setup. Which version of the Sentry SDK are you using? Does the crash happen only on real Android devices too?

Hi @antonis, here are some more info:

$ npx react-native info
info Fetching system and libraries information...
System:
  OS: macOS 15.0.1
  CPU: (12) arm64 Apple M2 Max
  Memory: 467.70 MB / 32.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 18.18.0
    path: ~/.nvm/versions/node/v18.18.0/bin/node
  Yarn:
    version: 1.22.22
    path: ~/.nvm/versions/node/v18.18.0/bin/yarn
  npm:
    version: 9.8.1
    path: ~/.nvm/versions/node/v18.18.0/bin/npm
  Watchman:
    version: 2024.09.23.00
    path: /opt/homebrew/bin/watchman
Managers:
  CocoaPods:
    version: 1.15.2
    path: /Users/<username>/.gem/ruby/3.2.2/bin/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 24.0
      - iOS 18.0
      - macOS 15.0
      - tvOS 18.0
      - visionOS 2.0
      - watchOS 11.0
  Android SDK:
    API Levels:
      - "23"
      - "30"
      - "31"
      - "33"
      - "34"
    Build Tools:
      - 30.0.2
      - 30.0.3
      - 31.0.0
      - 33.0.0
      - 34.0.0
    System Images:
      - android-31 | Google APIs ARM 64 v8a
      - android-33 | Google APIs ARM 64 v8a
      - android-34 | Google APIs ARM 64 v8a
      - android-34 | Google Play ARM 64 v8a
    Android NDK: Not Found
IDEs:
  Android Studio: 2023.1 AI-231.9392.1.2311.11076708
  Xcode:
    version: 16.0/16A242d
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 17.0.12
    path: /usr/bin/javac
  Ruby:
    version: 3.2.2
    path: /Users/<username>/.rubies/ruby-3.2.2/bin/ruby
npmPackages:
  "@react-native-community/cli": Not Found
  react:
    installed: 18.2.0
    wanted: 18.2.0
  react-native:
    installed: 0.72.0
    wanted: 0.72.0
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: false
iOS:
  hermesEnabled: true
  newArchEnabled: false

The Sentry SDK installed

"dependencies": {
    ...
    "@sentry/react-native": "^5.33.1",
    ...
}

Crash happens on Android & iOS devices but only on Release builds, not during development.

xgenem avatar Oct 07 '24 09:10 xgenem

Thank you for the added information @xgenem πŸ™‡ Just a heads-up that we haven’t been able to reproduce the issue yet. We will continue investigating and follow up with any updates.

antonis avatar Oct 09 '24 13:10 antonis

Hi @antonis this is noted. I have tried so many things already and the issue persists. I suspect it's other packages causing the issues, but after disabling Sentry the app does not crash in production. Thank you so much! Will wait.

xgenem avatar Oct 09 '24 15:10 xgenem

Hey @xgenem πŸ‘‹

I suspect it's other packages causing the issues, but after disabling Sentry the app does not crash in production.

Since we are not able to reproduce this on a new RN project with your configuration, could you provide more details on the dependencies you are using in case we can reproduce the crash? πŸ™‡

antonis avatar Oct 10 '24 11:10 antonis

Since we are not able to reproduce this on a new RN project with your configuration, could you provide more details on the dependencies you are using in case we can reproduce the crash? πŸ™‡

Hi @antonis below is the complete contents of my package.json file

{
  "name": "Project",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "build:ios": "react-native bundle --entry-file='index.js' --bundle-output='./ios/main.jsbundle' --dev=false --platform='ios'",
    "android": "react-native run-android",
    "ios": "react-native run-ios",
    "lint": "eslint .",
    "start": "react-native start",
    "test": "jest",
    "postinstall": "npx patch-package"
  },
  "dependencies": {
    "@bam.tech/react-native-image-resizer": "^3.0.5",
    "@gorhom/bottom-sheet": "^4.4.7",
    "@invertase/react-native-apple-authentication": "^2.3.0",
    "@react-native-async-storage/async-storage": "^1.18.1",
    "@react-native-camera-roll/camera-roll": "^5.4.0",
    "@react-native-clipboard/clipboard": "^1.11.2",
    "@react-native-community/blur": "^4.4.0",
    "@react-native-community/checkbox": "^0.5.15",
    "@react-native-community/netinfo": "^11.3.1",
    "@react-native-cookies/cookies": "^6.2.1",
    "@react-native-firebase/app": "20.1.0",
    "@react-native-firebase/crashlytics": "20.1.0",
    "@react-native-firebase/messaging": "20.1.0",
    "@react-native-firebase/remote-config": "20.1.0",
    "@react-native-google-signin/google-signin": "^11.0.0",
    "@react-native/gradle-plugin": "^0.74.85",
    "@react-navigation/native": "^6.1.17",
    "@react-navigation/native-stack": "^6.9.12",
    "@sentry/react-native": "^5.33.2",
    "@tanstack/react-query": "^4.29.7",
    "axios": "^1.4.0",
    "base-64": "^1.0.0",
    "date-fns": "^2.30.0",
    "jwt-decode": "^4.0.0",
    "lord-icon-element": "^4.1.1",
    "lottie-react-native": "^5.1.6",
    "moment": "2.30.1",
    "nativewind": "^2.0.11",
    "react": "18.2.0",
    "react-content-loader": "^6.2.1",
    "react-geocode": "^0.2.3",
    "react-native": "0.72.0",
    "react-native-agora-chat": "^1.1.1",
    "react-native-app-badge": "^0.1.5",
    "react-native-branch": "^5.8.0",
    "react-native-camera": "^4.2.1",
    "react-native-check-version": "^1.3.0",
    "react-native-config": "^1.5.1",
    "react-native-countdown-circle-timer": "^3.2.1",
    "react-native-countdown-component": "^2.7.1",
    "react-native-create-thumbnail": "^2.0.0-rc.2",
    "react-native-device-info": "^10.3.0",
    "react-native-document-picker": "^8.2.0",
    "react-native-dots-pagination": "^0.3.0",
    "react-native-element-dropdown": "^2.9.0",
    "react-native-fbsdk-next": "13",
    "react-native-file-access": "^2.6.0",
    "react-native-gesture-handler": "^2.17.1",
    "react-native-get-random-values": "^1.11.0",
    "react-native-gifted-chat": "^2.4.0",
    "react-native-image-picker": "^7.1.2",
    "react-native-instagram-login": "^2.0.6",
    "react-native-keyboard-aware-scroll-view": "^0.9.5",
    "react-native-linear-gradient": "^2.7.3",
    "react-native-maps": "1.15.3",
    "react-native-pager-view": "^6.2.0",
    "react-native-permissions": "^3.8.0",
    "react-native-push-notification": "^8.1.1",
    "react-native-raw-bottom-sheet": "^2.2.0",
    "react-native-reanimated": "^3.14.0",
    "react-native-responsive-screen": "^1.4.2",
    "react-native-safe-area-context": "^4.5.2",
    "react-native-screens": "^3.20.0",
    "react-native-sha256": "^1.4.10",
    "react-native-size-matters": "^0.4.2",
    "react-native-svg": "^13.9.0",
    "react-native-tab-view": "^3.5.2",
    "react-native-uuid": "^2.0.1",
    "react-native-video": "^6.5.0",
    "react-native-webview": "^11.26.1",
    "react-router-dom": "^6.22.1",
    "whatwg-fetch": "^3.6.2",
    "zustand": "4.5.2"
  },
  "reactNativePermissionsIOS": [
    "AppTrackingTransparency",
    "Camera",
    "FaceID",
    "MediaLibrary",
    "Microphone",
    "Notifications",
    "PhotoLibrary",
    "PhotoLibraryAddOnly",
    "Reminders",
    "StoreKit"
  ],
  "devDependencies": {
    "@babel/core": "^7.20.0",
    "@babel/preset-env": "^7.20.0",
    "@babel/runtime": "^7.20.0",
    "@react-native/eslint-config": "^0.72.2",
    "@react-native/metro-config": "^0.76.0-rc.3",
    "@tsconfig/react-native": "^3.0.5",
    "@types/jest": "^29.5.12",
    "@types/lodash": "4.17.5",
    "@types/metro-config": "^0.76.3",
    "@types/react": "^18.2.77",
    "@types/react-test-renderer": "^18.0.7",
    "babel-jest": "^29.2.1",
    "babel-plugin-module-resolver": "^5.0.2",
    "eslint": "^8.19.0",
    "eslint-plugin-simple-import-sort": "^12.0.0",
    "jest": "^29.2.1",
    "metro-react-native-babel-preset": "0.76.5",
    "prettier": "^2.4.1",
    "react-test-renderer": "18.2.0",
    "tailwindcss": "3.3.2",
    "typescript": "^5.4.5"
  },
  "jest": {
    "preset": "react-native"
  },
  "engines": {
    "node": ">=16"
  }
}

xgenem avatar Oct 16 '24 08:10 xgenem

Hello @antonis . Here is our package.json, just in case in will be useful for you

{
  "name": "Project",
  "version": "1.0.0",
  "private": true,
  "scripts": {
    "prebuild": "expo prebuild --clean",
    "start": "expo start --dev-client",
    "start:development": "NODE_ENV=development expo start --dev-client --clear",
    "android": "expo run:android",
    "android:development": "NODE_ENV=development expo run:android --device",
    "ios": "expo run:ios",
    "ios:development": "NODE_ENV=development expo run:ios --device",
    "check-eslint": "eslint .",
    "check-typescript": "bash -c tsc --noEmit",
    "prepare": "husky",
    "postinstall": "patch-package"
  },
  "dependencies": {
    "@config-plugins/react-native-blob-util": "8.0.0",
    "@config-plugins/react-native-pdf": "8.0.0",
    "@invertase/react-native-apple-authentication": "2.4.0",
    "@react-native-community/datetimepicker": "8.0.1",
    "@react-native-firebase/analytics": "20.5.0",
    "@react-native-firebase/app": "20.5.0",
    "@react-native-firebase/crashlytics": "20.5.0",
    "@react-native-firebase/messaging": "20.5.0",
    "@react-native-firebase/perf": "20.5.0",
    "@react-native-google-signin/google-signin": "13.1.0",
    "@react-navigation/bottom-tabs": "6.6.1",
    "@react-navigation/native": "6.1.18",
    "@react-navigation/native-stack": "6.11.0",
    "@reduxjs/toolkit": "2.2.7",
    "@shopify/flash-list": "1.7.1",
    "@tolgee/react": "5.29.1",
    "ajv": "8.17.1",
    "ajv-formats": "3.0.1",
    "axios": "1.7.7",
    "dayjs": "1.11.13",
    "expo": "51.0.37",
    "expo-asset": "10.0.10",
    "expo-build-properties": "0.12.5",
    "expo-clipboard": "6.0.3",
    "expo-dev-client": "4.0.28",
    "expo-font": "12.0.10",
    "expo-haptics": "13.0.1",
    "expo-image-picker": "15.0.7",
    "expo-linking": "6.3.1",
    "expo-local-authentication": "14.0.1",
    "expo-status-bar": "1.12.1",
    "fast-text-encoding": "1.0.6",
    "formik": "2.4.6",
    "google-libphonenumber": "3.2.38",
    "lodash": "4.17.21",
    "lz4js": "0.2.0",
    "numeral": "2.0.6",
    "patch-package": "8.0.0",
    "postinstall-postinstall": "2.1.0",
    "react": "18.2.0",
    "react-native": "0.74.5",
    "react-native-blob-util": "0.19.11",
    "react-native-bootsplash": "6.1.3",
    "react-native-chart-kit": "6.12.0",
    "react-native-country-flag": "2.0.2",
    "react-native-device-info": "13.0.0",
    "react-native-gesture-handler": "2.16.2",
    "react-native-get-random-values": "1.11.0",
    "react-native-keyboard-controller": "1.14.0",
    "react-native-keychain": "9.0.0",
    "react-native-localize": "3.2.1",
    "react-native-mmkv": "3.0.1",
    "react-native-pager-view": "6.3.0",
    "react-native-pdf": "6.7.5",
    "react-native-permissions": "4.1.5",
    "react-native-reanimated": "3.15.4",
    "react-native-reanimated-carousel": "4.0.0-canary.16",
    "react-native-safe-area-context": "4.11.0",
    "react-native-screens": "3.31.1",
    "react-native-tab-view": "3.5.2",
    "react-native-webview": "13.12.3",
    "react-redux": "9.1.2",
    "redux-persist": "6.0.0",
    "uuid": "10.0.0",
    "yup": "1.4.0"
  },
  "devDependencies": {
    "@babel/core": "7.25.2",
    "@babel/preset-env": "7.25.4",
    "@commitlint/cli": "19.5.0",
    "@commitlint/config-conventional": "19.5.0",
    "@ianvs/prettier-plugin-sort-imports": "4.3.1",
    "@react-native/eslint-config": "0.75.3",
    "@types/fast-text-encoding": "1.0.3",
    "@types/google-libphonenumber": "7.4.30",
    "@types/lodash": "4.17.9",
    "@types/lz4js": "0.2.1",
    "@types/numeral": "2.0.5",
    "@types/react": "18.2.79",
    "@types/react-native-keychain": "3.1.0",
    "@types/uuid": "10.0.0",
    "babel-plugin-module-resolver": "5.0.2",
    "eslint": "8.57.1",
    "eslint-config-airbnb": "19.0.4",
    "eslint-config-prettier": "9.1.0",
    "eslint-plugin-import": "2.30.0",
    "eslint-plugin-jsx-a11y": "6.10.0",
    "eslint-plugin-prettier": "5.2.1",
    "eslint-plugin-react": "7.37.0",
    "eslint-plugin-react-hooks": "4.6.2",
    "eslint-plugin-react-native": "4.1.0",
    "eslint-plugin-react-native-globals": "0.1.2",
    "eslint-plugin-unused-imports": "4.1.4",
    "husky": "9.1.6",
    "lint-staged": "15.2.10",
    "prettier": "3.3.3",
    "react-native-svg": "15.2.0",
    "react-native-svg-transformer": "1.5.0",
    "typescript": "5.3.3"
  },
  "expo": {
    "autolinking": {
      "exclude": ["expo-splash-screen"]
    }
  },
  "lint-staged": {
    "*.{js,jsx,ts,tsx}": ["prettier --write", "eslint --fix", "bash -c tsc --noEmit"]
  },
  "packageManager": "[email protected]+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
}

amakarevich11 avatar Oct 17 '24 08:10 amakarevich11

I went ahead and upgraded React Native version to 0.75.4 from 0.72.0 and re-added Sentry React Native. Seems like there were some updates on the Sentry side because it also got updated to version ^6.0.0 after running npx @sentry/wizard -i reactNative.

Couldn't really figure out the culprit Β―_(ツ)_/Β―

Sometimes, all we have to do is test different versions. Thanks for the attempt to help @antonis

xgenem avatar Oct 21 '24 15:10 xgenem

Thank you for the update @xgenem πŸ™‡

I went ahead and upgraded React Native version to 0.75.4 from 0.72.0 and re-added Sentry React Native. Seems like there were some updates on the Sentry side because it also got updated to version ^6.0.0

If I understand this correctly the problem is solved after the upgrades. Let us know if this is not the case πŸ™

antonis avatar Oct 21 '24 15:10 antonis

If I understand this correctly the problem is solved after the upgrades. Let us know if this is not the case πŸ™

Sorry if I was not clear on that but yes you're right. The app works without crashing now in production

xgenem avatar Oct 21 '24 15:10 xgenem

Leaving open till we confirm that the original issue is solved.

antonis avatar Oct 21 '24 16:10 antonis

This issue has gone three weeks without activity. In another week, I will close it.

But! If you comment or otherwise update it, I will reset the clock, and if you remove the label Waiting for: Community, I will leave it alone ... forever!


"A weed is but an unloved flower." ― Ella Wheeler Wilcox πŸ₯€

getsantry[bot] avatar Nov 12 '24 08:11 getsantry[bot]

We're planning to update sentry and RN to last version soon, I will keep you informed about issue status.

amakarevich11 avatar Nov 12 '24 08:11 amakarevich11

Hi, the issue disappeared after upgrading to RN 0.76.2 and expo SDK 52.0.7. Thank you for your help!

amakarevich11 avatar Nov 19 '24 15:11 amakarevich11