rkhachatryan commented on a change in pull request #16885:
URL: https://github.com/apache/flink/pull/16885#discussion_r692947292



##########
File path: 
flink-streaming-java/src/main/java/org/apache/flink/streaming/runtime/tasks/StreamTask.java
##########
@@ -881,12 +859,16 @@ private boolean areCheckpointsWithFinishedTasksEnabled() {
     }
 
     @Override
-    public void cleanUp() throws Exception {
+    public final void cleanUp() throws Exception {
         LOG.debug(
                 "Cleanup StreamTask (operators closed: {}, cancelled: {})",
                 closedOperators,
                 canceled);
 
+        failing = !canceled;
+
+        Exception suppressedException = 
runAndSuppressThrowable(this::cancelTask, null);

Review comment:
       In the current (master) version, the equivalent call from 
`runWithCleanUpOnFail` is **only** made if the task is **not** cancelled. That 
is, we call `cancelTask` if it wasn't cancelled **yet**.
   
   (regardless of which thread called `cancelTask()`, cleanup waits for 
`StreamTask.completionFuture` to complete) 
   
   So the check here should actually be: 
   ```
   if (!cancelled) {
           Exception suppressedException = 
runAndSuppressThrowable(this::cancelTask, null);
   }
   ```
   
   However, it doesn't prevent double cancellation. I'm going to add 
`AtomicBoolean` and use CAS when calling `cancelTask()`. WDYT?




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