1996fanrui commented on code in PR #27862:
URL: https://github.com/apache/flink/pull/27862#discussion_r3033571776


##########
flink-runtime/src/main/java/org/apache/flink/streaming/runtime/tasks/StreamTask.java:
##########
@@ -913,8 +913,14 @@ private CompletableFuture<Void> restoreStateAndGates(
                                             "Input gate request partitions"));
         }
 
-        return CompletableFuture.allOf(recoveredFutures.toArray(new 
CompletableFuture[0]))
-                .thenRun(mailboxProcessor::suspend);
+        // Return allOf result instead of thenRun result.
+        // thenRun returns a NEW future that completes after the callback 
finishes.
+        // Since suspend() runs on the async thread and just sends a poison 
mail,
+        // the mailbox loop can exit before suspend() returns, causing 
isDone() to be false.
+        CompletableFuture<Void> allRecoveredFuture =
+                CompletableFuture.allOf(recoveredFutures.toArray(new 
CompletableFuture[0]));
+        allRecoveredFuture.thenRun(mailboxProcessor::suspend);
+        return allRecoveredFuture;

Review Comment:
   This race condition only manifests with the new checkpointingDuringRecovery 
logic because `bufferFilteringCompleteFuture` completes much earlier (when 
state is written) than `stateConsumedFuture` (when state is consumed), creating 
a wider race window — so no separate JIRA is needed. The race is inherently 
non-deterministic and cannot be reliably reproduced in a unit test; the 
existing `checkState(allGatesRecoveredFuture.isDone())` in `restoreInternal()` 
serves as the runtime assertion.



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