You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@gluten.apache.org by ho...@apache.org on 2026/08/14 08:55:00 UTC

(gluten) branch main updated: [VL] Fail fast when NativeMemoryManager.hold() is called after release() instead of a native SIGSEGV

This is an automated email from the ASF dual-hosted git repository.

zhztheplayer pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/gluten.git


The following commit(s) were added to refs/heads/main by this push:
     new de3b4c40d6 [VL] Fail fast when NativeMemoryManager.hold() is called after release() instead of a native SIGSEGV
de3b4c40d6 is described below

commit de3b4c40d65ea749e6c99904ae85a8964a920bdd
Author: Kaifei Yi <yi...@apache.org>
AuthorDate: Fri Aug 14 16:54:54 2026 +0800

    [VL] Fail fast when NativeMemoryManager.hold() is called after release() instead of a native SIGSEGV
---
 .../scala/org/apache/gluten/memory/NativeMemoryManager.scala   | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/gluten-arrow/src/main/scala/org/apache/gluten/memory/NativeMemoryManager.scala b/gluten-arrow/src/main/scala/org/apache/gluten/memory/NativeMemoryManager.scala
index b1a9920cce..8fc7de1bbe 100644
--- a/gluten-arrow/src/main/scala/org/apache/gluten/memory/NativeMemoryManager.scala
+++ b/gluten-arrow/src/main/scala/org/apache/gluten/memory/NativeMemoryManager.scala
@@ -76,7 +76,15 @@ object NativeMemoryManager {
     private val released: AtomicBoolean = new AtomicBoolean(false)
 
     override def addSpiller(spiller: Spiller): Unit = spillers.append(spiller)
-    override def hold(): Unit = NativeMemoryManagerJniWrapper.hold(handle)
+    override def hold(): Unit = {
+      // hold() must run before release(). Reaching here after release means a broken teardown
+      // ordering, so surface it instead of dereferencing a freed native handle silently.
+      if (released.get()) {
+        throw new GlutenException(
+          s"Cannot hold memory manager instance that has already been released: $handle")
+      }
+      NativeMemoryManagerJniWrapper.hold(handle)
+    }
     override def getHandle(): Long = handle
     override def release(): Unit = {
       if (!released.compareAndSet(false, true)) {


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@gluten.apache.org
For additional commands, e-mail: commits-help@gluten.apache.org