diff --git a/plugin/trino-hive/src/main/java/io/trino/plugin/hive/s3/TrinoS3FileSystem.java b/plugin/trino-hive/src/main/java/io/trino/plugin/hive/s3/TrinoS3FileSystem.java index 6fbec96f4761..1bfd8fb5db45 100644 --- a/plugin/trino-hive/src/main/java/io/trino/plugin/hive/s3/TrinoS3FileSystem.java +++ b/plugin/trino-hive/src/main/java/io/trino/plugin/hive/s3/TrinoS3FileSystem.java @@ -1481,6 +1481,7 @@ private static class TrinoS3StreamingOutputStream private byte[] buffer; private int bufferSize; + private boolean closed; private boolean failed; // Mutated and read by main thread; mutated just before scheduling upload to background thread (access does not need to be thread safe) private boolean multipartUploadStarted; @@ -1548,6 +1549,11 @@ public void flush() public void close() throws IOException { + if (closed) { + return; + } + closed = true; + if (failed) { try { abortUpload();