GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — fix: serialise native handle lifetime against concurrent close by andygrove · Pull Request #115 · apache/datafusion-java Conversation
Member
Which issue does this PR close?
Rationale for this change
if (nativeHandle == 0) throw new IllegalStateException(...); someNativeCall(nativeHandle, ...); The check and the use are separate operations on a non-volatile field, so a The docs said "not thread-safe", which made this defensible but not Reading the native side showed the problem is entirely Java-side. Every What changes are included in this PR?A new package-private
Every non-consuming method became Two properties drove the design:
The monitor is held only for bookkeeping, never across a JNI call, so The Rust-side Argument validation stays in its existing position relative to the closed check Are these changes tested?Yes, three new suites (18 tests):
I verified the tests actually detect the bug by temporarily removing the drain The full suite is green (360 tests), as are Are there any user-facing changes?No API changes, but the documented contract is stronger, and the Javadoc plus
The docs are explicit that this covers the handle's lifetime and not the
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactionsSessionContext and DataFrame each held a raw `long nativeHandle` guarded by `if (nativeHandle == 0) throw`. The check and the JNI call were separate operations, so a concurrent close() could free the native Box between them and leave the other thread dereferencing freed memory. Introduce a package-private NativeHandle that owns the pointer. Every call pins the handle for its duration (acquire/release); close() and the consuming operations claim it, waiting for in-flight calls to drain before handing the pointer back to Rust to be freed. acquire() never blocks, which is what lets the two-handle set operations and joins pin both DataFrames without a lock-ordering hazard. A read/write lock would not: its readers queue behind a waiting writer, so opposing pin orders with closes interleaved could deadlock. claim() is the only blocking operation and always makes progress, since a thread holding a pin is inside a native call and never claims. No native change is needed. Every non-consuming JNI entry point already takes a shared reference, and DataFusion's SessionContext and DataFrame are Send + Sync, so only the handle's lifetime had to be serialised. Closes apache#40
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ReviewersNo reviewsUh oh!
There was an error while loading. Please reload this page. AssigneesNo one assignedLabels
None yet
ProjectsMilestoneNo milestoneDevelopmentSuccessfully merging this pull request may close these issues. bug: SessionContext.close() / DataFrame.close() race with concurrent JNI calls (use-after-free)Uh oh!
There was an error while loading. Please reload this page. Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later. |
| You are visitor 01402520 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |