This is a repro of the abort seen in the following issue: getsentry/sentry-java#2604. It is based on a basic Android Studio app template. The only things that changed were the following:
- text content and size of the centered
TextView
, which is clickable to trigger the repro. - the
MainActivity
starts the Android method traceronCreate
in background sampling mode (using the same parameters as the Android SDK). - an
OnClickListener
calling the native code that triggers the abort.
-
The JNI function starts a native thread (appending it to the pthread thread list)
-
the native thread attaches to the ART (appending it to the ART thread list)
-
but exits before detaching (-> the thread remains in the ART thread list)
-
the JNI function joins that thread ( removing it from the pthread thread list)
invalid_pthread_repro/app/src/main/cpp/native-lib.cpp
Lines 10 to 35 in 0a1679f
- Calling
pthread_exit()
orpthread_join()
before an attached thread could be detached is illegal. - But that doesn't necessarily mean that it will fail at that point.
- Since the two thread lists are now out of sync, the ART method tracer will retrieve a thread from the ART thread list that is no longer maintained in
pthread
state - The first function requiring a look-up in the tracer sampling path seems to be
pthread_getcpuclockid()
[1], which aborts with a fatal log if the provided pthread_t cannot be found [2].