ColinLeeo commented on code in PR #18869:
URL: https://github.com/apache/iotdb/pull/18869#discussion_r4320808675


##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/memory/MemoryPool.java:
##########
@@ -241,6 +305,15 @@ public void deRegisterFragmentInstanceFromQueryMemoryMap(
         // forceDeregister == true, after all 
LocalSourceChannel/LocalSourceHandles are closed.
         return;
       }
+      // Pending requests must not outlive their FI registration. Cancel 
before removing the
+      // account so another query's free() cannot retry a request against a 
missing FI. Do not
+      // hold the registration lock while notifying cancellation listeners.
+      if (fragmentRelatedMemory != null) {
+        for (MemoryReservationFuture<Void> future :
+            fragmentRelatedMemory.pendingReservations.values()) {
+          tryCancel(future);
+        }
+      }

Review Comment:
   Agreed. The local fix protects waiter publication and deregistration with 
the same FragmentMemoryReservation monitor. Deregistration marks the account as 
closed before removing it, and publication refuses requests against a closed 
account. Retries encountering a closed account detach the waiter and continue, 
without cancelling or completing its future.
   Added a deterministic regression reproducing this interleaving and verifying 
that another query’s waiter is still admitted when memory is freed. There is 
also coverage for recreating an FI with the same ID. Both tests fail on 
788a995c75 and pass with the local fix. The changes have not been pushed yet.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to