From 67a9377c6eb6f02150b1ddbaf39922f29508e8d6 Mon Sep 17 00:00:00 2001 From: Mark Schreiber Date: Mon, 2 Oct 2023 11:37:59 -0400 Subject: [PATCH] ensure FS is closed when calling closeFileSystem --- .../amazon/nio/spi/s3/S3FileSystemProvider.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/main/java/software/amazon/nio/spi/s3/S3FileSystemProvider.java b/src/main/java/software/amazon/nio/spi/s3/S3FileSystemProvider.java index 2e8927e9..269ffb8c 100644 --- a/src/main/java/software/amazon/nio/spi/s3/S3FileSystemProvider.java +++ b/src/main/java/software/amazon/nio/spi/s3/S3FileSystemProvider.java @@ -26,6 +26,8 @@ import software.amazon.awssdk.services.s3.paginators.ListObjectsV2Publisher; import software.amazon.awssdk.transfer.s3.S3TransferManager; import software.amazon.awssdk.transfer.s3.model.CopyRequest; +import software.amazon.nio.spi.s3.config.S3NioSpiConfiguration; +import software.amazon.nio.spi.s3.util.S3FileSystemInfo; import software.amazon.nio.spi.s3.util.TimeOutUtils; import java.io.IOException; @@ -40,6 +42,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; +import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; @@ -52,12 +55,9 @@ import java.util.stream.Collectors; import static java.nio.file.LinkOption.NOFOLLOW_LINKS; -import java.util.HashMap; import static java.util.concurrent.TimeUnit.MINUTES; import static software.amazon.awssdk.http.HttpStatusCode.FORBIDDEN; import static software.amazon.awssdk.http.HttpStatusCode.NOT_FOUND; -import software.amazon.nio.spi.s3.config.S3NioSpiConfiguration; -import software.amazon.nio.spi.s3.util.S3FileSystemInfo; import static software.amazon.nio.spi.s3.util.TimeOutUtils.TIMEOUT_TIME_LENGTH_1; import static software.amazon.nio.spi.s3.util.TimeOutUtils.logAndGenerateExceptionOnTimeOut; @@ -246,6 +246,13 @@ public void closeFileSystem(FileSystem fs) { cache.remove(key); return; } } + try { + if(fs.isOpen()) { + fs.close(); + } + } catch (IOException e) { + throw new RuntimeException(e); + } } /**