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

Compilation Error in Sentry React Native 6.10.0: Custom Allocator std::allocator_traits Issue

Open archan0621 opened this issue 1 year ago • 38 comments

[!IMPORTANT] Note from the maintainers: This issue affects many libraries, not just Sentry. It is caused by Xcode 16.3 removing a non-standard C++ feature. Read on for details. Note that if all else fails, using Xcode 16.2 should still work.

  • We shipped a fix for this in @sentry/react-native 6.10.0.
    • If you use sentry-dart, upgrade to 8.14.0+. sentry-cocoa includes the fix in release 8.46.0+.
    • If you use one of the fixed versions and still encounter the issue, it is very likely that you use another affected library (read on for more info on popular affected libraries).
    • If you update all your known affected dependencies to fixed versions, and still encounter the problem, make sure you perform clean builds (delete all build artefacts, including derived data). If that doesn't help, try removing them one by one and take it from there.
  • React Native versions 0.76.8 and lower are affected - you should upgrade to 0.76.9+ to fix this issue. They will not release fixes for versions before 0.76. You can read up on the details in their GH issue
  • Expo is also affected, they set up a separate info page about packages and fix versions: https://expo.dev/changelog/xcode-16-3-patches

Even though it is fixed on our side, we'll keep this issue open for a little while longer for easier discovery (ppl often don't search closed issues).


What React Native libraries do you use?

React Native without Frameworks

Are you using sentry.io or on-premise?

sentry.io (SaS)

@sentry/react-native SDK Version

6.10.0

How does your development environment look like?

After upgrading from iOS sdk version 18.4, our iOS project fails to compile. The error appears to be related to a custom allocator (ThreadMetadataInnerHashMapAllocator) used within Sentry’s profiling code. Specifically, the compiler reports that the custom allocator does not meet the requirements of std::allocator_traits. For example, error messages include references to “rebinding an allocator to the same type should result in using the same object” and “No type named ‘value_type’”, which suggest that the allocator’s definitions (possibly regarding const qualifiers and required member types) are not in line with standard expectations.

Sentry.init()

Sentry.init({
  dsn: '',
  tracesSampleRate: 1.0,
  integrations: [new HttpClient()],
  beforeSend(event) {
    event.tags = {...event.tags, version: version};
    return event;
  },
  sendDefaultPii: true,
});

Steps to Reproduce

  1. Upgrade iOS SDK to 18.4
  2. Clean the iOS project by deleting Podfile.lock, the Pods/ directory, and Xcode’s DerivedData.
  3. Run pod install --repo-update in the iOS directory.
  4. Attempt to build the project in Xcode.

Expected Result

Build Success

Actual Result

Build failed with error

/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS18.4.sdk/usr/include/c++/v1/__memory/allocator_traits.h:378:17 Static assertion failed due to requirement 'is_same<std::allocator<const sentry::profiling::ThreadMetadataCache::ThreadHandleMetadataPair>, std::allocator<int>>::value': [allocator.requirements] states that rebinding an allocator to the same type should result in the original allocator


/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS18.4.sdk/usr/include/c++/v1/__memory/allocator.h:95:17 Static assertion failed due to requirement '!is_const<const sentry::profiling::ThreadMetadataCache::ThreadHandleMetadataPair>::value': std::allocator does not support const types


/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS18.4.sdk/usr/include/c++/v1/__type_traits/enable_if.h:28:58 No type named 'type' in 'std::enable_if<false, int>'; 'enable_if' cannot be used to disable this declaration


/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS18.4.sdk/usr/include/c++/v1/vector:427:50 No type named 'value_type' in 'std::allocator<const sentry::profiling::ThreadMetadataCache::ThreadHandleMetadataPair>'

archan0621 avatar Apr 01 '25 02:04 archan0621

@archan0621 thanks for reporting! Did you also switch Xcode versions? Can you tell us the previous iOS/Xcode versions you built with?

@armcknight this looks related to https://github.com/getsentry/sentry-cocoa/issues/4886 (see second error in the log) but that was fixed in sentry-cocoa 8.46.0 and is part of @sentry/react-native 6.10.0. could you please take a look?

cc @krystofwoldrich

kahest avatar Apr 01 '25 06:04 kahest

Experiencing the same issue as @archan0621.

No build issues with Xcode 16.2 (with iOS 18.2 SDK), only became an issue with 16.3 (yesterday), coinciding with the release of iOS 18.4 and its SDK.

Jaltaire avatar Apr 01 '25 06:04 Jaltaire

Thanks @Jaltaire - this is most likely caused by Xcode 16.3 then and should already be fixed, but seems like something slipped through. We'll investigate and report back here

kahest avatar Apr 01 '25 06:04 kahest

Thank you for checking, @kahest. I confirmed that there are no build issues with Xcode 16.2, so I downgraded to that version and the problem was resolved. I also noticed that Xcode 16.3 has issues with React Native, as mentioned in the react-native repository. Thanks again for your help!

archan0621 avatar Apr 01 '25 08:04 archan0621

Thank you for reporting @archan0621 🙇

I confirmed that there are no build issues with Xcode 16.2, so I downgraded to that version and the problem was resolved.

Glad this worked for you.

I've tested with a new RN 0.78.0 project (npx @react-native-community/cli@latest init --version 0.78.0) and the latest (6.10.0) Sentry RN SDK and was able to compile and run the project on an iOS 18.4 target without issues.

I also noticed that Xcode 16.3 has issues with React Native, as mentioned in the react-native repository.

Indeed there is a React Native issue that causes a compilation error with Xcode 16.3 up to 0.76.8

Which version of React Native are you using?

antonis avatar Apr 01 '25 09:04 antonis

Can confirm Sentry module not compiling after upgrading to Xcode 16.3

Not affected by above RN issue due to upgrading to "react-native": "~0.77.1",

Important to note upgrading from "@sentry/react-native": "~6.3.0" (recommended by expo) to "@sentry/react-native": "~6.10.0"

vladcos avatar Apr 01 '25 12:04 vladcos

Thank you for iterating on this @vladcos 🙇

Not affected by above RN issue due to upgrading to "react-native": "~0.77.1",

I've tested on a new react-native 0.77.1 project with Xcode 16.3 and did not get a compile error.

My package.json

{
  "name": "test0771",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "android": "react-native run-android",
    "ios": "react-native run-ios",
    "lint": "eslint .",
    "start": "react-native start",
    "test": "jest"
  },
  "dependencies": {
    "@sentry/react-native": "^6.10.0",
    "react": "18.3.1",
    "react-native": "0.77.1"
  },
  "devDependencies": {
    "@babel/core": "^7.25.2",
    "@babel/preset-env": "^7.25.3",
    "@babel/runtime": "^7.25.0",
    "@react-native-community/cli": "15.0.1",
    "@react-native-community/cli-platform-android": "15.0.1",
    "@react-native-community/cli-platform-ios": "15.0.1",
    "@react-native/babel-preset": "0.77.1",
    "@react-native/eslint-config": "0.77.1",
    "@react-native/metro-config": "0.77.1",
    "@react-native/typescript-config": "0.77.1",
    "@types/jest": "^29.5.13",
    "@types/react": "^18.2.6",
    "@types/react-test-renderer": "^18.0.0",
    "eslint": "^8.19.0",
    "jest": "^29.6.3",
    "prettier": "2.8.8",
    "react-test-renderer": "18.3.1",
    "typescript": "5.0.4"
  },
  "engines": {
    "node": ">=18"
  }
}

Important to note upgrading from "@sentry/react-native": "~6.3.0" (recommended by expo) to "@sentry/react-native": "~6.10.0"

I've also tested with the latest Expo after bumping react native to 0.77.1 (from 0.76.8 that was the default in Expo 52) and was able to compile and run on a

My Expo package.json

{
  "name": "testexpo",
  "main": "expo-router/entry",
  "version": "1.0.0",
  "scripts": {
    "start": "expo start",
    "reset-project": "node ./scripts/reset-project.js",
    "android": "expo run:android",
    "ios": "expo run:ios",
    "web": "expo start --web",
    "test": "jest --watchAll",
    "lint": "expo lint"
  },
  "jest": {
    "preset": "jest-expo"
  },
  "dependencies": {
    "@expo/vector-icons": "^14.0.2",
    "@react-navigation/bottom-tabs": "^7.2.0",
    "@react-navigation/native": "^7.0.14",
    "@sentry/react-native": "^6.10.0",
    "expo": "~52.0.42",
    "expo-blur": "~14.0.3",
    "expo-constants": "~17.0.8",
    "expo-font": "~13.0.4",
    "expo-haptics": "~14.0.1",
    "expo-linking": "~7.0.5",
    "expo-router": "~4.0.19",
    "expo-splash-screen": "~0.29.22",
    "expo-status-bar": "~2.0.1",
    "expo-symbols": "~0.2.2",
    "expo-system-ui": "~4.0.9",
    "expo-web-browser": "~14.0.2",
    "react": "18.3.1",
    "react-dom": "18.3.1",
    "react-native": "0.77.1",
    "react-native-gesture-handler": "~2.20.2",
    "react-native-reanimated": "~3.16.1",
    "react-native-safe-area-context": "4.12.0",
    "react-native-screens": "~4.4.0",
    "react-native-web": "~0.19.13",
    "react-native-webview": "13.12.5"
  },
  "devDependencies": {
    "@babel/core": "^7.25.2",
    "@types/jest": "^29.5.12",
    "@types/react": "~18.3.12",
    "@types/react-native": "^0.73.0",
    "@types/react-test-renderer": "^18.3.0",
    "jest": "^29.2.1",
    "jest-expo": "~52.0.6",
    "react-test-renderer": "18.3.1",
    "typescript": "^5.3.3"
  },
  "private": true
}

Could you share more information on your project setup to reproduce the issue? 🙏

antonis avatar Apr 01 '25 13:04 antonis

It seems the issue isn't limited to React as it also happens in our Ionic+Vue project, since Xcode 16.3

Ericlm avatar Apr 01 '25 14:04 Ericlm

The root cause is likely going to be rather widespread because Xcode 16.3 removed a non-standard C++ feature that was somewhat widely used and will affect many libraries and their downstream consumers.


According to the GH issue on react-native, for RN, only RN 0.76 is affected, and a fix will be released for it.

If you experience this issue with RN 0.77+ AND with @sentry/react-native 6.10.0+ please let us know.

kahest avatar Apr 01 '25 14:04 kahest

Also affects RN 0.75.4 over here ✋ Will try upgrading @sentry/react-native to 6.10.0 tomorrow and report back.


Update: upgrading Sentry worked, but RN 0.76 now breaks the build, due to the same issue on the RCTFolly pod.

Related to: https://github.com/getsentry/sentry-react-native/issues/4715#issuecomment-2772071720 Everything seems okay on @sentry/react-native to 6.10.0 ✅

jeremyallison avatar Apr 01 '25 19:04 jeremyallison

Same error happening with our flutter app :/

g-coutos avatar Apr 01 '25 22:04 g-coutos

It looks like you faced an issue after updating your Mac to version 15.3.2 and Xcode to version 16.3. After downgrading to Xcode 16.2, the build worked successfully.

To download Xcode 16.2, you can visit Apple's developer downloads page.

If you need any more help, feel free to ask!

JohnKHW avatar Apr 02 '25 02:04 JohnKHW

+1 same issue with ios 18.4 (latest xcode update).

NiharR027 avatar Apr 02 '25 02:04 NiharR027

Also experiencing the same with the following:

  • Xcode 16.3
  • iOS 18.4
  • react-native 0.77.2
  • @sentry/react-native 6.10.0
  • expo 52.0.42

The app kind of perform the intial build, but when it starts I get this error

non-std C++ exception

RCTFatal
-[RCTJSThreadManager _handleError:]
__26-[RCTJSThreadManager init]_block_invoke_2
facebook::react::RCTMessageThread::tryFunc(std::__1::function<void ()> const&)
facebook::react::RCTMessageThread::runOnQueue(std::__1::function<void ()>&&)::$_0::operator()() const
decltype(std::declval<facebook::react::RCTMessageThread::runOnQueue(std::__1::function<void ()>&&)::$_0&>()()) std::__1::__invoke[abi:de190102]<facebook::react::RCTMessageThread::runOnQueue(std::__1::function<void ()>&&)::$_0&>(facebook::react::RCTMessageThread::runOnQueue(std::__1::function<void ()>&&)::$_0&)
void std::__1::__invoke_void_return_wrapper<void, true>::__call[abi:de190102]<facebook::react::RCTMessageThread::runOnQueue(std::__1::function<void ()>&&)::$_0&>(facebook::react::RCTMessageThread::runOnQueue(std::__1::function<void ()>&&)::$_0&)
std::__1::__function::__alloc_func<facebook::react::RCTMessageThread::runOnQueue(std::__1::function<void ()>&&)::$_0, std::__1::allocator<facebook::react::RCTMessageThread::runOnQueue(std::__1::function<void ()>&&)::$_0>, void ()>::operator()[abi:de190102]()
std::__1::__function::__func<facebook::react::RCTMessageThread::runOnQueue(std::__1::function<void ()>&&)::$_0, std::__1::allocator<facebook::react::RCTMessageThread::runOnQueue(std::__1::function<void ()>&&)::$_0>, void ()>::operator()()
std::__1::__function::__value_func<void ()>::operator()[abi:de190102]() const
std::__1::function<void ()>::operator()() const
invocation function for block in facebook::react::RCTMessageThread::runAsync(std::__1::function<void ()>)
__CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__
__CFRunLoopDoBlocks
__CFRunLoopRun
CFRunLoopRunSpecific
+[RCTJSThreadManager runRunLoop]
__NSThread__start__
_pthread_start
thread_start

dkrabdev avatar Apr 02 '25 04:04 dkrabdev

@dkrabdev this looks like an issue in React Native itself - please check the GH issue: https://github.com/facebook/react-native/issues/50411

kahest avatar Apr 02 '25 10:04 kahest

Just dropping in to confirm that upgrading @sentry/react-native to 6.10.0 fixes this issue on React Native 0.77.0, when using Xcode 16.3!

appfr3d avatar Apr 02 '25 10:04 appfr3d

Same error happening with our flutter app :/

For sentry-dart SDK, the fix was part of the 8.14.0 release. If you get the same error with 8.14.0+ and you can rule out that the error is caused by another library, please reply in https://github.com/getsentry/sentry-dart/issues/2838.

kahest avatar Apr 02 '25 16:04 kahest

Heads-up - Expo is has a bunch of fixes out for their affected packages: https://expo.dev/changelog/xcode-16-3-patches

kahest avatar Apr 02 '25 18:04 kahest

Just dropping in to confirm that upgrading @sentry/react-native to 6.10.0 fixes this issue on React Native 0.77.0, when using Xcode 16.3!

"@sentry/react-native": "6.10.0",
"react-native": "0.73.11",

not works for me

ombogdan avatar Apr 03 '25 08:04 ombogdan

@ombogdan you need to bump your react-native dependency to 0.77+. They are also working on a fix for 0.76.x, but it's not out yet. They will not release fixes for versions before 0.76. You can read up on the details in their GH issue.

kahest avatar Apr 03 '25 08:04 kahest