Skip to content

fix(core): Retry native module resolution to prevent silent event drops#5981

Open
antonis wants to merge 3 commits intomainfrom
antonis/fix-turbomodule-race-5508
Open

fix(core): Retry native module resolution to prevent silent event drops#5981
antonis wants to merge 3 commits intomainfrom
antonis/fix-turbomodule-race-5508

Conversation

@antonis
Copy link
Copy Markdown
Contributor

@antonis antonis commented Apr 13, 2026

📢 Type of change

  • Bugfix

📜 Description

The RNSentry TurboModule reference is resolved once at module load time (wrapper.ts:48). In production Hermes bytecode builds, JS execution can start before the TurboModule registry is fully populated, causing getRNSentryModule() to return undefined permanently. This silently disables native transport and drops all events.

The fix re-resolves the native module in isNativeAvailable() if the initial resolution returned undefined. By the time Sentry.init() calls this method (milliseconds after module load), TurboModules are registered and the module resolves correctly.

Changes:

  • const RNSentrylet RNSentry to allow re-assignment
  • isNativeAvailable() retries getRNSentryModule() if RNSentry is undefined

💡 Motivation and Context

Fixes RN-447

Users report that events are silently dropped in production builds (Hermes + New Architecture) when Sentry.init() is the first statement after an early return guard. Adding any statement (e.g., console.log('test')) before Sentry.init() resolves the issue, pointing to a race condition in TurboModule registration timing.

💚 How did you test it?

  • Added unit test simulating the race condition (module initially undefined, then available)
  • All existing tests pass (78/78 wrapper tests, full suite green)
  • On-device testing with Pixel 8 Pro, Android 16, production Hermes build

📝 Checklist

  • I added tests to verify changes
  • No new PII added or SDK only sends newly added PII if sendDefaultPII is enabled
  • I updated the docs if needed.
  • I updated the wizard if needed.
  • All tests passing
  • No breaking changes

🔮 Next steps

  • Separately investigate the __SENTRY_OPTIONS__ + autoInitializeNativeSdk code path which has a related but distinct silent event drop bug in 8.x when useNativeInit: false is combined with options in the Expo plugin config.

The RNSentry TurboModule reference is resolved once at module load time.
In production Hermes bytecode builds, JS execution can start before the
TurboModule registry is fully populated, causing getRNSentryModule() to
return undefined permanently. This silently disables native transport
and drops all events.

Re-resolve the native module in isNativeAvailable() if the initial
resolution returned undefined. By the time Sentry.init() calls this
method, TurboModules are registered and the module resolves correctly.

Fixes #5508

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 13, 2026

Semver Impact of This PR

None (no version bump detected)

📋 Changelog Preview

This is how your changes will appear in the changelog.
Entries from this PR are highlighted with a left border (blockquote style).


  • fix(core): Retry native module resolution to prevent silent event drops by antonis in #5981
  • ci: Gate size analysis on ready-to-merge label for PRs by antonis in #5963
  • chore(deps): update Android SDK to v8.38.0 by github-actions in #5971
  • chore(deps): update Sentry Android Gradle Plugin to v6.4.0 by github-actions in #5974
  • chore(deps): update Cocoa SDK to v9.10.0 by github-actions in #5972
  • chore(deps): update JavaScript SDK to v10.48.0 by github-actions in #5975
  • chore(deps): bump actions/github-script from 8 to 9 by dependabot in #5980
  • chore(deps): bump actions/create-github-app-token from 3.0.0 to 3.1.1 by dependabot in #5979
  • chore(deps): update Bundler Plugins to v5.2.0 by github-actions in #5968
  • chore(deps): bump axios from 1.13.5 to 1.15.0 by dependabot in #5978
  • chore(deps): bump addressable from 2.8.7 to 2.9.0 in /performance-tests by dependabot in #5969
  • chore(deps): bump basic-ftp from 5.2.0 to 5.2.2 by dependabot in #5977
  • fix(profiling): Fix app start transaction profile timestamp offset by antonis in #5962
  • fix(android): Use componentStack as fallback for missing error stack traces by antonis in #5965
  • chore(deps): bump addressable from 2.8.7 to 2.9.0 in /samples/react-native-macos by dependabot in #5967
  • chore(deps): bump addressable from 2.8.7 to 2.9.0 in /samples/react-native by dependabot in #5966
  • fix(ios): Add SENTRY_PROJECT_ROOT env var for monorepo support by antonis in #5961
  • feat(ios): Add attachAllThreads option by antonis in #5960
  • fix(core): Lazy-load Metro internal modules to prevent Expo 55 import errors by lucas-zimerman in #5958
  • chore(deps): update Cocoa SDK to v9.9.0 by github-actions in #5956
  • chore(deps): update Maestro to v2.4.0 by github-actions in #5955
  • Feat: Fallback to stacktrace parsing by lucas-zimerman in #5946
  • fix(ci): Bump Node to 22 in size-analysis and testflight workflows by antonis in #5954
  • feat(playground): Open Sentry in desktop browser from Expo apps by antonis in #5947

Plus 6 more


🤖 This preview updates automatically when you update the PR.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 13, 2026

Fails
🚫 Pull request is not ready for merge, please add the "ready-to-merge" label to the pull request

Generated by 🚫 dangerJS against 1c56d9d

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@antonis
Copy link
Copy Markdown
Contributor Author

antonis commented Apr 13, 2026

@sentry review

@antonis
Copy link
Copy Markdown
Contributor Author

antonis commented Apr 13, 2026

@cursor review

Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit f6c6b67. Configure here.

@antonis antonis marked this pull request as ready for review April 13, 2026 11:48
Copy link
Copy Markdown
Contributor

@alwx alwx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks!

@linear-code
Copy link
Copy Markdown

linear-code bot commented Apr 13, 2026

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants