Skip to content

fix(hdfs_3_3): detach only threads attached by libhdfs - #47

Merged
Xuanwo merged 1 commit into
Xuanwo:mainfrom
peterxcli:codex/fix-hdfs-thread-destructor-upstream
Sep 22, 2026
Merged

Xuanwo merged 1 commit into
Xuanwo:mainfrom
peterxcli:codex/fix-hdfs-thread-destructor-upstream

Conversation

@peterxcli

Copy link
Copy Markdown
Contributor

Summary

  • use GetEnv to distinguish JVM-owned threads from detached native threads
  • record whether libhdfs attached or created the current thread's JVM environment
  • call GetJavaVM and DetachCurrentThread only for libhdfs-owned attachments

Motivation

The POSIX hdfsThreadDestructor unconditionally dereferences the cached JNIEnv and detaches the thread. For a thread already attached by the JVM, that environment can be freed before the native TLS destructor runs, causing a use-after-free and a jump through an invalid JNI function table.

This matches HDFS-16021 and was reproduced downstream in apache/datafusion-comet#5023.

This PR is intentionally scoped to the hdfs_3_3 POSIX source selected by the affected downstream. Older vendored Hadoop snapshots use different TLS layouts and need separate adaptations.

Testing

  • cargo test --features hdfs_3_3,vendored on macOS ARM64 with JDK 17: 13 passed
  • cargo fmt --all -- --check
  • 110 fresh-JVM downstream regression runs of ParquetReadFromFakeHadoopFsSuite
  • all six macOS jobs passed on apache/datafusion-comet#5036, including the native build and scan suite containing the regression test

@peterxcli

Copy link
Copy Markdown
Contributor Author

@Xuanwo any chance you could take a look at this? I'd really appreciate any insight you could provide! This would help me fix a lot of flaky tests in DataFusion Comet: apache/datafusion-comet#5036 (comment)

@Xuanwo
Xuanwo merged commit 3f957fe into Xuanwo:main Sep 22, 2026
9 of 10 checks passed
@peterxcli
peterxcli deleted the codex/fix-hdfs-thread-destructor-upstream branch September 22, 2026 09:02
@peterxcli

Copy link
Copy Markdown
Contributor Author

@Xuanwo thanks!

peterxcli added a commit to peterxcli/datafusion-comet that referenced this pull request Sep 26, 2026
hdfs-sys 0.3.1 includes the libhdfs thread destructor fix
(Xuanwo/hdfs-sys#47), so the workspace [patch.crates-io] pin is no
longer needed.
comphead pushed a commit to comphead/arrow-datafusion-comet that referenced this pull request Sep 29, 2026
* fix: pin patched hdfs-sys for safe thread cleanup

* deps: use hdfs-sys 0.3.1 release instead of git patch

hdfs-sys 0.3.1 includes the libhdfs thread destructor fix
(Xuanwo/hdfs-sys#47), so the workspace [patch.crates-io] pin is no
longer needed.

---------

Co-authored-by: Andy Grove <[email protected]>
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