From 7f2a58e46cdf0fd797aa58c6b0c8035913d34402 Mon Sep 17 00:00:00 2001 From: eliran goshen Date: Fri, 20 Mar 2026 10:44:30 -0700 Subject: [PATCH] Fix JNI registration bug: HermesSamplingProfiler.disable() calls enable() (#56174) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Summary: `HermesSamplingProfiler::registerNatives()` maps the JNI `"disable"` method to `HermesSamplingProfiler::enable` instead of `HermesSamplingProfiler::disable` (copy-paste bug). This means calling `HermesSamplingProfiler.disable()` from Java actually calls `enable()` again, which corrupts the sampling thread state. This causes a SIGABRT crash on Android when any profiling tool (e.g. Sentry) calls `disable()` to stop profiling: ``` Fatal signal 6 (SIGABRT), code -1 (SI_QUEUE) in tid (hermes-sampling) Abort message: 'invalid pthread_t passed to pthread_kill' ``` The fix is a one-character change: `::enable` → `::disable`. Related issue: https://github.com/facebook/react-native/issues/56120 ## Changelog: [ANDROID] [FIXED] - Fix HermesSamplingProfiler.disable() JNI registration calling enable() instead of disable() Pull Request resolved: https://github.com/facebook/react-native/pull/56174 Test Plan: This is a copy-paste bug fix visible by code inspection. The correct `disable()` C++ implementation already exists (line 20-24, calls `hermesAPI->disableSamplingProfiler()`) — it was just never invoked due to the incorrect JNI registration. Verified in production at Expensify: with this fix applied via patch-package, the SIGABRT crash no longer occurs when Sentry Hermes profiling is enabled. Reviewed By: javache Differential Revision: D97489621 Pulled By: cortinico fbshipit-source-id: 2109040ba2a5fecf1fd5d41f541d15161af1bd8b --- .../jni/react/hermes/instrumentation/HermesSamplingProfiler.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/react-native/ReactAndroid/src/main/jni/react/hermes/instrumentation/HermesSamplingProfiler.cpp b/packages/react-native/ReactAndroid/src/main/jni/react/hermes/instrumentation/HermesSamplingProfiler.cpp index 6bd061f26b9..77015a6b757 100644 --- a/packages/react-native/ReactAndroid/src/main/jni/react/hermes/instrumentation/HermesSamplingProfiler.cpp +++ b/packages/react-native/ReactAndroid/src/main/jni/react/hermes/instrumentation/HermesSamplingProfiler.cpp @@ -34,7 +34,7 @@ void HermesSamplingProfiler::dumpSampledTraceToFile( void HermesSamplingProfiler::registerNatives() { javaClassLocal()->registerNatives({ makeNativeMethod("enable", HermesSamplingProfiler::enable), - makeNativeMethod("disable", HermesSamplingProfiler::enable), + makeNativeMethod("disable", HermesSamplingProfiler::disable), makeNativeMethod( "dumpSampledTraceToFile", HermesSamplingProfiler::dumpSampledTraceToFile),