bug: SessionContext.close() / DataFrame.close() race with concurrent JNI calls (use-after-free)
@andygrove y travaille déjà.
Depuis le 6/8/2026.
Évaluation
Cette issue n'a pas encore été évaluée.
Description
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.
- Langage dominant
- Java
- Étoiles
- 32
- Forks
- 12
- Métriques de merge des PR
- Aucune PR mergée en 30 j
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de apache/datafusion-java
-
Difficulté 5/5 Plus d'une semaine Accessibilité débutants 35/100
apache/datafusion-java#116 ·
-
Difficulté 5/5 Plus d'une semaine Accessibilité débutants 25/100
apache/datafusion-java#112 ·
-
enhancement
Difficulté 5/5 Plus d'une semaine Accessibilité débutants 42/100
apache/datafusion-java#96 ·
-
enhancement
Difficulté 5/5 Plus d'une semaine Accessibilité débutants 38/100
apache/datafusion-java#95 ·
-
Create first release Ouverteenhancement
Difficulté 4/5 3-5 jours Accessibilité débutants 35/100
apache/datafusion-java#86 · 3 commentaires ·
Toutes les issues de apache/datafusion-java
Issues similaires
-
bug untriaged
Difficulté 2/5 1-3 heures Accessibilité débutants 84/100
opensearch-project/ml-commons#5094 ·
-
bug
Difficulté 2/5 1-3 heures Accessibilité débutants 85/100
-
emitter:client:csharp feature
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
-
affects/8.10 affects/8.9 component/clients kind/bug likelihood/mid severity/mid
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
-
Two open-case totals on one screen: the Programs tile says 15,858 and the nav badge says 15,868 Ouvertebug frontend maui-pilot
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100