Fix native SIGSEGV when hold() races with release() on NativeMemoryManager - #12714
Fix native SIGSEGV when hold() races with release() on NativeMemoryManager#12714yikf wants to merge 1 commit into
Conversation
|
@zhztheplayer could you please take a look if you have time, thanks. |
There was a problem hiding this comment.
Pull request overview
This PR fixes a race in NativeMemoryManager where hold() could call into native code after release() had freed the underlying native handle, leading to a JVM crash (SIGSEGV) under concurrent task teardown and iterator close.
Changes:
- Add an instance-level lock to make
hold()andrelease()mutually exclusive around native JNI calls. - Make
hold()a safe no-op when the memory manager has already been released, preventing use-after-free.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@yikf Thanks. I thought |
|
Thanks @zhztheplayer. You're right that in the normal flow the iterator is closed before the
In the normal single-threaded path both run on the task thread, and
So |
|
btw, i found this case at other PR ci pipeline, https://github.com/apache/gluten/actions/runs/31071855879/job/92523319304?pr=12697 |
|
@zhztheplayer friendly re-ping, please take a look again if you have time. |
|
@yikf Would you help check the failed CI? |
|
@zhztheplayer It also failed due to similar issues. I submitted a PR: #12740 |
What changes are proposed in this pull request?
NativeMemoryManager.hold()called the nativehold(handle)JNI method without checking whether the manager had already been released. When a task tears down its runtime (release()frees the native handle) while another thread is still closing an output iterator viaColumnarBatchOutIterator.close0() -> memoryManager().hold(),hold()dereferences a freed handle and crashes the JVM with a SIGSEGV (SEGV_MAPERR= use-after-free).Surfaced as a flaky native crash in CI running
GlutenSparkScriptTransformationSuite(itsTRANSFORM ... USINGtests close the columnar output iterator on a feed thread concurrently with task teardown):From
hs_err_pid*.log:How was this patch tested?
flaky test, existed test to verify.
Was this patch authored or co-authored using generative AI tooling?
Yes, AI-assisted, Generated-by: Claude claude-opus-4-8.