Skip to content

Commit e57209a

Browse files
author
Dmitriy Fingerman
committed
HIVE-29268: Iceberg: Close catalog in Catalogs.loadTable() to fix resource leak from open ResolvingFileIO
1 parent ad55d58 commit e57209a

File tree

1 file changed

+11
-1
lines changed
  • iceberg/iceberg-handler/src/main/java/org/apache/iceberg/mr

1 file changed

+11
-1
lines changed

iceberg/iceberg-handler/src/main/java/org/apache/iceberg/mr/Catalogs.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,17 @@ private static Table loadTable(Configuration conf, String tableIdentifier, Strin
111111

112112
if (catalog.isPresent()) {
113113
Preconditions.checkArgument(tableIdentifier != null, "Table identifier not set");
114-
return catalog.get().loadTable(TableIdentifier.parse(tableIdentifier));
114+
115+
if (catalog.get() instanceof AutoCloseable) {
116+
try (AutoCloseable ignored = (AutoCloseable) catalog.get()) {
117+
return catalog.get().loadTable(TableIdentifier.parse(tableIdentifier));
118+
} catch (Exception e) {
119+
throw new RuntimeException("Failed to close catalog", e);
120+
}
121+
} else {
122+
// fallback if not AutoCloseable
123+
return catalog.get().loadTable(TableIdentifier.parse(tableIdentifier));
124+
}
115125
}
116126

117127
Preconditions.checkArgument(tableLocation != null, "Table location not set");

0 commit comments

Comments
 (0)