diff --git a/plugin/trino-exchange-filesystem/src/main/java/io/trino/plugin/exchange/filesystem/local/LocalFileSystemExchangeStorage.java b/plugin/trino-exchange-filesystem/src/main/java/io/trino/plugin/exchange/filesystem/local/LocalFileSystemExchangeStorage.java index 62ae3485d393..f3a5ff4308c9 100644 --- a/plugin/trino-exchange-filesystem/src/main/java/io/trino/plugin/exchange/filesystem/local/LocalFileSystemExchangeStorage.java +++ b/plugin/trino-exchange-filesystem/src/main/java/io/trino/plugin/exchange/filesystem/local/LocalFileSystemExchangeStorage.java @@ -159,8 +159,13 @@ public synchronized Slice read() return null; } - if (sliceInput != null && sliceInput.isReadable()) { - return sliceInput.readSlice(sliceInput.readInt()); + if (sliceInput != null) { + if (sliceInput.isReadable()) { + return sliceInput.readSlice(sliceInput.readInt()); + } + else { + sliceInput.close(); + } } ExchangeSourceFile sourceFile = sourceFiles.poll(); diff --git a/plugin/trino-exchange-hdfs/src/main/java/io/trino/plugin/exchange/hdfs/HadoopFileSystemExchangeStorage.java b/plugin/trino-exchange-hdfs/src/main/java/io/trino/plugin/exchange/hdfs/HadoopFileSystemExchangeStorage.java index 19608c00573d..09b0614ea679 100644 --- a/plugin/trino-exchange-hdfs/src/main/java/io/trino/plugin/exchange/hdfs/HadoopFileSystemExchangeStorage.java +++ b/plugin/trino-exchange-hdfs/src/main/java/io/trino/plugin/exchange/hdfs/HadoopFileSystemExchangeStorage.java @@ -174,8 +174,13 @@ public synchronized Slice read() return null; } - if (sliceInput != null && sliceInput.isReadable()) { - return sliceInput.readSlice(sliceInput.readInt()); + if (sliceInput != null) { + if (sliceInput.isReadable()) { + return sliceInput.readSlice(sliceInput.readInt()); + } + else { + sliceInput.close(); + } } ExchangeSourceFile sourceFile = sourceFiles.poll();