RussellSpitzer commented on code in PR #18540:
URL: https://github.com/apache/iceberg/pull/18540#discussion_r4405536377


##########
core/src/main/java/org/apache/iceberg/util/Tasks.java:
##########
@@ -500,65 +500,62 @@ private static boolean causedByInterruption(Throwable 
throwable) {
 
   @SuppressWarnings("checkstyle:CyclomaticComplexity")
   private static Collection<Throwable> waitFor(Collection<Future<?>> futures) {
-    while (true) {
-      int numFinished = 0;
+    try {
+      // block on each unfinished future in turn until all are done
       for (Future<?> future : futures) {
-        if (future.isDone()) {
-          numFinished += 1;
-        }
-      }
-
-      if (numFinished == futures.size()) {
-        List<Throwable> uncaught = Lists.newArrayList();
-        // all of the futures are done, get any uncaught exceptions
-        for (Future<?> future : futures) {
+        if (!future.isDone()) {
           try {
             future.get();
+          } catch (ExecutionException | CancellationException ignored) {
+            // collected once all futures are done
+          }
+        }
+      }
+    } catch (InterruptedException e) {
+      LOG.warn("Interrupted while waiting for tasks to finish", e);
 
-          } catch (InterruptedException e) {
-            LOG.warn("Interrupted while getting future results", e);
-            for (Throwable t : uncaught) {
-              e.addSuppressed(t);
-            }
-            Thread.currentThread().interrupt();
-            throw new RuntimeException(e);
+      for (Future<?> future : futures) {
+        future.cancel(true);
+      }
+      Thread.currentThread().interrupt();
+      throw new RuntimeException(e);
+    }
 
-          } catch (CancellationException e) {
-            // ignore cancellations
+    List<Throwable> uncaught = Lists.newArrayList();
+    // all of the futures are done, get any uncaught exceptions
+    for (Future<?> future : futures) {
+      try {
+        future.get();
 
-          } catch (ExecutionException e) {
-            Throwable cause = e.getCause();
-            if (cause instanceof Error) {
-              for (Throwable t : uncaught) {
-                cause.addSuppressed(t);
-              }
-              throw (Error) cause;
-            }
+      } catch (InterruptedException e) {

Review Comment:
   Is this reachable now? It feels like we have already called get on every 
future that wasn't done by the time we got to it. So all the "get" requests now 
should be interruption free.
   
   I think we have to keep the catch, but let's just rethrow here. I think at 
the moment it makes it look like the logic is duplicated with the call above 
and this is just a noop. 



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