From d80db6c9e5f2a3b10526e0f7afcf011794d9378f Mon Sep 17 00:00:00 2001 From: Steve Loughran Date: Tue, 18 Oct 2022 14:53:02 +0100 Subject: [PATCH] HADOOP-18476. Abfs and S3A FileContext bindings to close wrapped filesystems in finalizer (#4966) This is to try and close the underlying filesystems when the FileContext APIs are used. Without this, threads may be leaked --- .../src/main/java/org/apache/hadoop/fs/s3a/S3A.java | 13 +++++++++++-- .../java/org/apache/hadoop/fs/azurebfs/Abfs.java | 9 +++++++++ .../java/org/apache/hadoop/fs/azurebfs/Abfss.java | 9 +++++++++ 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/S3A.java b/hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/S3A.java index 78643cc5e0..ec433fa95c 100644 --- a/hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/S3A.java +++ b/hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/S3A.java @@ -33,10 +33,10 @@ */ @InterfaceAudience.Public @InterfaceStability.Evolving -public class S3A extends DelegateToFileSystem{ +public class S3A extends DelegateToFileSystem { public S3A(URI theUri, Configuration conf) - throws IOException, URISyntaxException { + throws IOException, URISyntaxException { super(theUri, new S3AFileSystem(), conf, "s3a", false); } @@ -54,4 +54,13 @@ public String toString() { sb.append('}'); return sb.toString(); } + + /** + * Close the file system; the FileContext API doesn't have an explicit close. + */ + @Override + protected void finalize() throws Throwable { + fsImpl.close(); + super.finalize(); + } } diff --git a/hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/Abfs.java b/hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/Abfs.java index 32df942238..e595b2f4ef 100644 --- a/hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/Abfs.java +++ b/hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/Abfs.java @@ -43,4 +43,13 @@ public class Abfs extends DelegateToFileSystem { public int getUriDefaultPort() { return -1; } + + /** + * Close the file system; the FileContext API doesn't have an explicit close. + */ + @Override + protected void finalize() throws Throwable { + fsImpl.close(); + super.finalize(); + } } diff --git a/hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/Abfss.java b/hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/Abfss.java index c33265ce32..ba20bbb5d7 100644 --- a/hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/Abfss.java +++ b/hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/Abfss.java @@ -43,4 +43,13 @@ public class Abfss extends DelegateToFileSystem { public int getUriDefaultPort() { return -1; } + + /** + * Close the file system; the FileContext API doesn't have an explicit close. + */ + @Override + protected void finalize() throws Throwable { + fsImpl.close(); + super.finalize(); + } }