philo-he opened a new issue, #13786:
URL: https://github.com/apache/gluten/issues/13786

   ### Description
   
   ### Background
   
   #13728 (GLUTEN-13729) fixed native threads that Gluten attaches to the JVM 
but never detaches. When such a thread exits, the JVM keeps a `JavaThread` for 
a dead pthread, and a later thread dump crashes the executor in 
`pthread_getcpuclockid`.
   
   The fix detaches lazily attached threads from a pthread TSD destructor that 
defers itself by one destructor round. That ordering is needed because 
libhdfs's `hdfsThreadDestructor` detaches every thread it has used, at thread 
exit, using its cached `JNIEnv*`. If Gluten detached first, libhdfs would use a 
freed `JNIEnv*` (GLUTEN-11895).
   
   HDFS-16021 (apache/hadoop#8739) changes libhdfs to reuse an existing 
attachment and to detach only threads it attached itself. Once every libhdfs 
Gluten may load includes that fix, the ordering constraint goes away.
   
   ### Proposal
   
   As suggested by @zhztheplayer in 
https://github.com/apache/gluten/pull/13728#issuecomment-7140049184, move JNI 
attach/detach for Gluten's native threads into `ThreadManager` 
(`cpp/core/threads/ThreadManager.cc`):
   
   - Attach each pool thread to the JVM once, when it starts.
   - Detach it once, at the end of the thread body.
   - Assert at runtime that a thread calling into Java is attached, instead of 
attaching lazily in `attachCurrentThreadAsDaemonOrThrow`.
   - Remove the deferred TSD detach (`cpp/core/jni/JniThreadExit.{h,cc}`) and 
the related workarounds.
   
   This makes the attach/detach lifecycle explicit and checkable: attach once, 
detach once. The cost is attaching every pool thread up front, which should not 
be visible in performance.
   
   ### Prerequisite
   
   Velox does not bundle libhdfs. It loads the deployment's `libhdfs.so` from 
`HADOOP_HOME` or `ARROW_LIBHDFS_DIR` at runtime, and Gluten cannot easily tell 
which version it loaded. HDFS-16021 is currently only on Hadoop trunk and 
branch-3.5. With an older libhdfs (e.g. 3.3.x or 3.4.x), a detach at the end of 
the thread body would run before `hdfsThreadDestructor` and bring back 
GLUTEN-11895 for threads that read HDFS.
   
   So this should be done once the minimum Hadoop version Gluten supports 
includes HDFS-16021. S3-only and local-file deployments never load libhdfs and 
are not affected either way.
   
   ### References
   
   - #13728, #13729: current fix
   - #11896 (GLUTEN-11895): libhdfs `JNIEnv*` crash after an early detach
   - HDFS-16021, apache/hadoop#8739: libhdfs detaches only threads it attached
   
   This issue was drafted with the assistance of AI (Claude Opus 5.5).
   
   ### Gluten version
   
   None


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to