From e488750ad289cbbb6ff1d88906a4ec9acf48cc84 Mon Sep 17 00:00:00 2001 From: Mark Vieira Date: Wed, 5 Jan 2022 19:04:02 -0800 Subject: [PATCH] Handle wrapped IO exceptions in test cluster distribution syncing (#82288) (#82299) Third attempt at sorting out this problem after #82154 didn't do the trick. The issue is that `FileTreeIterator` wraps the root cause exception in an `UncheckedIOException` so to detect this scenario properly we actually have to inspect the cause. --- .../gradle/testclusters/ElasticsearchNode.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/build-tools/src/main/java/org/elasticsearch/gradle/testclusters/ElasticsearchNode.java b/build-tools/src/main/java/org/elasticsearch/gradle/testclusters/ElasticsearchNode.java index ff8930ed42c84..064f45de14f99 100644 --- a/build-tools/src/main/java/org/elasticsearch/gradle/testclusters/ElasticsearchNode.java +++ b/build-tools/src/main/java/org/elasticsearch/gradle/testclusters/ElasticsearchNode.java @@ -1216,10 +1216,15 @@ private void sync(Path sourceRoot, Path destinationRoot, BiConsumer syncMethod.accept(destination, source); } }); - } catch (NoSuchFileException e) { - // Ignore these files that are sometimes left behind by the JVM - if (e.getFile() == null || e.getFile().contains(".attach_pid") == false) { - throw new UncheckedIOException(e); + } catch (UncheckedIOException e) { + if (e.getCause() instanceof NoSuchFileException) { + NoSuchFileException cause = (NoSuchFileException) e.getCause(); + // Ignore these files that are sometimes left behind by the JVM + if (cause.getFile() == null || cause.getFile().contains(".attach_pid") == false) { + throw new UncheckedIOException(cause); + } + } else { + throw e; } } catch (IOException e) { throw new UncheckedIOException("Can't walk source " + sourceRoot, e);