facebook / facebook/hermes

When is Sampler::platformSuspendVMAndWalkStack called?

Open
#1,853 14 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
JavaScript
Stars
11.3k
Forks
859
Avg merge
1h 30m
Merged PRs (30d)
3

Description

## Problem

Hey folks, I'm investigating a crash on Android that provides me with the following error:

```sh
invalid pthread_t 0x passed to pthread_kill
```

Comes with a stack trace like this:

```sh
*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
pid: 0, tid: 5131 >>> com.my.app <<<

backtrace:
#00 pc 0x000000000007123c /apex/com.android.runtime/lib64/bionic/libc.so (abort+160)
#01 pc 0x0000000000082c28 /apex/com.android.runtime/lib64/bionic/libc.so (__pthread_internal_find(long, char const*)+196)
#02 pc 0x0000000000082b44 /apex/com.android.runtime/lib64/bionic/libc.so (__pthread_internal_gettid(long, char const*)+12)
#03 pc 0x0000000000083948 /apex/com.android.runtime/lib64/bionic/libc.so (pthread_kill+52)
#04 pc 0x00000000001105e0 /data/app/~~GVAFjiv3MRHi6wN_jyFNGQ==/com.my.app-dfsyqHFTuzXmYnuve2e92g==/split_config.arm64_v8a.apk!libhermes.so (BuildId: b06c77a49801680608345e3c05bd59aba90e9f19)
#05 pc 0x0000000000110a60 /data/app/~~GVAFjiv3MRHi6wN_jyFNGQ==/com.my.app-dfsyqHFTuzXmYnuve2e92g==/split_config.arm64_v8a.apk!libhermes.so (BuildId: b06c77a49801680608345e3c05bd59aba90e9f19)
#06 pc 0x000000000011095c /data/app/~~GVAFjiv3MRHi6wN_jyFNGQ==/com.my.app-dfsyqHFTuzXmYnuve2e92g==/split_config.arm64_v8a.apk!libhermes.so (BuildId: b06c77a49801680608345e3c05bd59aba90e9f19)
#07 pc 0x0000000000110d78 /data/app/~~GVAFjiv3MRHi6wN_jyFNGQ==/com.my.app-dfsyqHFTuzXmYnuve2e92g==/split_config.arm64_v8a.apk!libhermes.so (BuildId: b06c77a49801680608345e3c05bd59aba90e9f19)
#08 pc 0x0000000000111480 /data/app/~~GVAFjiv3MRHi6wN_jyFNGQ==/com.my.app-dfsyqHFTuzXmYnuve2e92g==/split_config.arm64_v8a.apk!libhermes.so (BuildId: b06c77a49801680608345e3c05bd59aba90e9f19)
#09 pc 0x0000000000082600 /apex/com.android.runtime/lib64/bionic/libc.so (__pthread_start(void*)+184)
#10 pc 0x0000000000074a58 /apex/com.android.runtime/lib64/bionic/libc.so (__start_thread+68)
````

This *looks* a lot like the issue described in https://github.com/facebook/hermes/issues/491, although I'm running:

React Native: 0.79.6
Expo: 53.0.19
React Native Reanimated: 3.19.2

I know that original issue was marked as resolved in React Native Reanimated (not actually for Hermes to solve). This update was said to have fixed it: https://github.com/software-mansion/react-native-reanimated/pull/2842

Although I'm seeing in my current Reanimated version, the profiler is no longer disabled: https://github.com/software-mansion/react-native-reanimated/blob/3.19.2/packages/react-native-reanimated/Common/cpp/worklets/WorkletRuntime/ReanimatedRuntime.cpp#L32

So my hypothesis is that React Native Reanimated introduced a regression to their codebase, but I'm missing some information (and thus unable to reproduce for them or for you).

I'm writing here to ask a question about how `Sampler::platformSuspendVMAndWalkStack` is called. My understanding is that the original issue was that Reanimated was using a Hermes runtime with profiling enabled, and something about `Sampler::platformSuspendVMAndWalkStack` was breaking, because it calls `pthread_kill`, and Reanimated *might* be using a different thread (thus resulting in the original stack trace).

But I'm seeing this crash in production. It's coming to me through the Google Play Console crashes panel. I don't understand why a production app might hit this code path - shouldn't we only see it when doing profiling? Are my users profiling the app? Or is there some other way we can hit `pthread_kill` in the Hermes codebase?

Or perhaps I've misunderstood what "profiling" is - which is what I'm seeking clarity on (and why I opened a discussion, not a bug report, haha).

## Solution

If you can clarify when that method might be called, it'll help me figure out how to reproduce this error better. I can bring that back to Reanimated with a real reproducer. Right now I only see this in the wild and I'm having trouble reproducing it locally (even when running a profiler from React dev tools).

Thanks in advance!

Contributor guide

Open the contributing guide

Research direction

Read packages/react-native-reanimated/Common/cpp/worklets/WorkletRuntime/ReanimatedRuntime.cpp and trace calls to Sampler::platformSuspendVMAndWalkStack in Hermes. Compare the profiler-related paths with the Android crash context; done means documenting when the method is called and identifying what reproduction information is needed.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, javascript, react-native
Domain
mobile-dev, performance
Issue type
Documentation
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.