RussellSpitzer commented on code in PR #18540:
URL: https://github.com/apache/iceberg/pull/18540#discussion_r4405548757
##########
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:
Maybe
```java
} catch (InterruptedException e) {
throw new IllegalStateException("Completed future was interrupted", e);
}
```
--
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]