From e8c121163404b63b178bce9f355fa45eed8ba7af Mon Sep 17 00:00:00 2001 From: xuyu <11161569@vivo.com> Date: Sun, 20 Oct 2024 16:33:43 +0800 Subject: [PATCH] [core] Fix writer close avoid memory leak --- .../paimon/iceberg/manifest/IcebergManifestFile.java | 3 ++- .../main/java/org/apache/paimon/manifest/ManifestFile.java | 7 ++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/paimon-core/src/main/java/org/apache/paimon/iceberg/manifest/IcebergManifestFile.java b/paimon-core/src/main/java/org/apache/paimon/iceberg/manifest/IcebergManifestFile.java index d04cf3576a11..911627db072c 100644 --- a/paimon-core/src/main/java/org/apache/paimon/iceberg/manifest/IcebergManifestFile.java +++ b/paimon-core/src/main/java/org/apache/paimon/iceberg/manifest/IcebergManifestFile.java @@ -110,9 +110,10 @@ public List rollingWrite( () -> createWriter(sequenceNumber), targetFileSize.getBytes()); try { writer.write(entries); - writer.close(); } catch (Exception e) { throw new RuntimeException(e); + } finally { + writer.close(); } return writer.result(); } diff --git a/paimon-core/src/main/java/org/apache/paimon/manifest/ManifestFile.java b/paimon-core/src/main/java/org/apache/paimon/manifest/ManifestFile.java index 38181a8234aa..df0ac1f6528f 100644 --- a/paimon-core/src/main/java/org/apache/paimon/manifest/ManifestFile.java +++ b/paimon-core/src/main/java/org/apache/paimon/manifest/ManifestFile.java @@ -93,9 +93,14 @@ public List write(List entries) { RollingFileWriter writer = createRollingWriter(); try { writer.write(entries); - writer.close(); } catch (Exception e) { throw new RuntimeException(e); + } finally { + try { + writer.close(); + } catch (IOException e) { + throw new RuntimeException(e); + } } return writer.result(); }