From 40310632a8c95010b876223a872915788123b01b Mon Sep 17 00:00:00 2001 From: chenjian2664 Date: Tue, 2 Sep 2025 11:20:45 +0800 Subject: [PATCH] Fix closing `TransactionLogEntryIterator` The iterator was not closed when caching transaction log entries, which could lead to resource leaks --- .../deltalake/transactionlog/TransactionLogEntries.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/plugin/trino-delta-lake/src/main/java/io/trino/plugin/deltalake/transactionlog/TransactionLogEntries.java b/plugin/trino-delta-lake/src/main/java/io/trino/plugin/deltalake/transactionlog/TransactionLogEntries.java index 55038dbe9c52..75486754e41e 100644 --- a/plugin/trino-delta-lake/src/main/java/io/trino/plugin/deltalake/transactionlog/TransactionLogEntries.java +++ b/plugin/trino-delta-lake/src/main/java/io/trino/plugin/deltalake/transactionlog/TransactionLogEntries.java @@ -24,6 +24,7 @@ import io.trino.spi.TrinoException; import java.io.BufferedReader; +import java.io.Closeable; import java.io.IOException; import java.io.InputStreamReader; import java.util.Iterator; @@ -60,7 +61,9 @@ public TransactionLogEntries(long entryNumber, TrinoInputFile inputFile, DataSiz this.cachedEntries = Optional.empty(); } else { - this.cachedEntries = Optional.of(ImmutableList.copyOf(new TransactionLogEntryIterator(entryNumber, inputFile))); + try (TransactionLogEntryIterator logEntryIterator = new TransactionLogEntryIterator(entryNumber, inputFile)) { + this.cachedEntries = Optional.of(ImmutableList.copyOf(logEntryIterator)); + } } } catch (IOException e) { @@ -122,6 +125,7 @@ public long getRetainedSizeInBytes() private static final class TransactionLogEntryIterator extends AbstractIterator + implements Closeable { private final long entryNumber; private final Location location; @@ -163,6 +167,7 @@ protected DeltaLakeTransactionLogEntry computeNext() return deltaLakeTransactionLogEntry; } + @Override public void close() { try {