FrankChen021 commented on code in PR #20321:
URL: https://github.com/apache/druid/pull/20321#discussion_r4481005674


##########
multi-stage-query/src/main/java/org/apache/druid/msq/querykit/ChainedProcessorManager.java:
##########
@@ -129,12 +169,18 @@ public R result()
   @Override
   public void close()
   {
-    if (!closed) {
+    synchronized (lock) {
+      if (closed) {
+        return;
+      }
       closed = true;
-      CloseableUtils.closeAndWrapExceptions(() -> CloseableUtils.closeAll(
-          first,
-          restFuture.isDone() ? FutureUtils.getUnchecked(restFuture, false) : 
null
-      ));
     }
+
+    // Close outside the lock: restFuture can no longer change, since 
checkFirstProcessorComplete() does nothing
+    // once closed.
+    CloseableUtils.closeAndWrapExceptions(() -> CloseableUtils.closeAll(
+        first,
+        restFuture.isDone() ? FutureUtils.getUnchecked(restFuture, false) : 
null

Review Comment:
   [P2] Complete pending next futures on close
   
   **Finding:** When the first phase has returned empty but its processors are 
still completing, `next()` can already be waiting on `nextFromRest()`. If the 
run then fails or is cancelled, `close()` sets `closed`, so 
`checkFirstProcessorComplete()` will never set `restFuture`; because this close 
path no longer cancels it, the returned future remains permanently pending and 
retains the waiting callback.
   
   **Suggestion:** Restore close-time cancellation of `restFuture`, or 
otherwise complete every outstanding `nextFromRest()` future after marking the 
manager closed.



-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to