bug: SessionContext.close() / DataFrame.close() race with concurrent JNI calls (use-after-free)
@andygrove がすでに取り組んでいます。
2026年8月6日 から。
評価
この issue はまだ評価されていません。
説明
Describe the bug
SessionContext and DataFrame hold their native pointer in a plain
long nativeHandle. Every public method follows the pattern:
if (nativeHandle == 0) throw new IllegalStateException(...);
someNativeCall(nativeHandle, ...);
…and close() does:
if (nativeHandle != 0) {
closeSessionContext(nativeHandle);
nativeHandle = 0;
}
If thread A is mid-method on a context and thread B calls close() on
the same context, the read in A and the write+free in B race:
- A reads
nativeHandle(non-zero), passes it to JNI. - B sets
nativeHandle = 0and the Rust side drops theBox. - A's JNI call dereferences a freed
*const SessionContext→ UAF.
Even the nativeHandle == 0 guard is not safe — it's a TOCTOU. The
same shape applies to DataFrame (each method reads nativeHandle,
then calls JNI).
To Reproduce
No reproducer exists yet. A two-thread test running a tight loop of
ctx.sql(...).count() against ctx.close() on an ASan-instrumented
native build would surface it deterministically; can write one if the
maintainers want to see it first.
Expected behavior
One of:
- Document the UB explicitly. Today the Javadoc says contexts are
"not thread-safe" and warns about concurrentsql/register*/
close, but the consequence ("can produce a use-after-free") is
already spelled out — so it's arguably already expected, and this
issue is just a tracking marker so a future maintainer doesn't get
surprised. - Atomic handle + reference count. Use
AtomicLongfor the
handle and reference-count on the Rust side so close() defers until
in-flight calls drain. Closer to what JNA-style bindings do. - Per-instance lock. Wrap every JNI call in a synchronized
block. Simplest, but kills any potential concurrency on independent
read-only operations.
Additional context
Not a regression — the documented contract already excludes concurrent
use. Filing for visibility ahead of the first multi-threaded user (a
server, a Flink/Spark integration, etc.) hitting it in production
rather than dev. Cross-references SessionContext.java and
DataFrame.java; same shape will need attention any time a new
long-lived handle is added.
- 主要言語
- Java
- スター
- 32
- フォーク
- 12
- PR マージ指標
- 30日以内にマージされた PR はありません
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
apache/datafusion-java のほかの issue
-
難易度 5/5 1週間以上 初心者へのやさしさ 35/100
apache/datafusion-java#116 ·
-
難易度 5/5 1週間以上 初心者へのやさしさ 25/100
apache/datafusion-java#112 ·
-
enhancement
難易度 5/5 1週間以上 初心者へのやさしさ 42/100
apache/datafusion-java#96 ·
-
enhancement
難易度 5/5 1週間以上 初心者へのやさしさ 38/100
apache/datafusion-java#95 ·
-
Create first release オープンenhancement
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
apache/datafusion-java#86 · コメント 3 件 ·
apache/datafusion-java の issue をすべて見る
似ている issue
-
bug untriaged
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
opensearch-project/ml-commons#5094 ·
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
-
emitter:client:csharp feature
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
-
affects/8.10 affects/8.9 component/clients kind/bug likelihood/mid severity/mid
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
-
Two open-case totals on one screen: the Programs tile says 15,858 and the nav badge says 15,868 オープンbug frontend maui-pilot
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100