Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SPARK-50274][CORE] Guard against use-after-close in DirectByteBuffer…
…OutputStream ### What changes were proposed in this pull request? `DirectByteBufferOutputStream#close()` calls `StorageUtils.dispose()` to free its direct byte buffer. This puts the object into an unspecified and dangerous state after being closed, and can cause unpredictable JVM crashes if it the object is used after close. This PR makes this safer by modifying `close()` to place the object into a known-closed state, and modifying all methods to assert not closed. To minimize the performance impact from the extra checks, this PR also changes `DirectByteBufferOutputStream#buffer` from `private` to `private[this]`, which should produce more efficient direct field accesses. ### Why are the changes needed? Improves debuggability for users of DirectByteBufferOutputStream such as PythonRunner. ### Does this PR introduce _any_ user-facing change? No. ### How was this patch tested? Added a test in DirectByteBufferOutputStreamSuite to verify that use after close throws IllegalStateException. ### Was this patch authored or co-authored using generative AI tooling? No. Closes apache#48807 from ankurdave/SPARK-50274-DirectByteBufferOutputStream-checkNotClosed. Authored-by: Ankur Dave <ankurdave@gmail.com> Signed-off-by: Hyukjin Kwon <gurwls223@apache.org>
- Loading branch information