diff --git a/runners/core-construction-java/src/main/java/org/apache/beam/runners/core/construction/External.java b/runners/core-construction-java/src/main/java/org/apache/beam/runners/core/construction/External.java index 534a2b5fe0e6..93a1ade474a5 100644 --- a/runners/core-construction-java/src/main/java/org/apache/beam/runners/core/construction/External.java +++ b/runners/core-construction-java/src/main/java/org/apache/beam/runners/core/construction/External.java @@ -19,6 +19,7 @@ import static org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.base.Preconditions.checkArgument; +import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.nio.file.Files; @@ -391,7 +392,8 @@ private static List resolveArtifacts( .build()) .getReplacementsList()) { Path path = Files.createTempFile("beam-artifact", ""); - try (FileOutputStream fout = new FileOutputStream(path.toFile())) { + File artifactFile = path.toFile(); + try (FileOutputStream fout = new FileOutputStream(artifactFile)) { for (Iterator it = retrievalStub.getArtifact( ArtifactApi.GetArtifactRequest.newBuilder().setArtifact(artifact).build()); @@ -409,6 +411,8 @@ private static List resolveArtifacts( .build() .toByteString()) .build()); + // Delete beam-artifact temp File on program exit + artifactFile.deleteOnExit(); } return resolved; }