This is an automated email from the ASF dual-hosted git repository.

danny0405 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/hudi.git


The following commit(s) were added to refs/heads/master by this push:
     new c8647ce670e [HUDI-8794] Make sure the log file has been closed and 
then remove the shutdown hook (#12542)
c8647ce670e is described below

commit c8647ce670eb516e69557485aff512f61d9449d6
Author: TheR1sing3un <[email protected]>
AuthorDate: Fri Jan 3 14:12:14 2025 +0800

    [HUDI-8794] Make sure the log file has been closed and then remove the 
shutdown hook (#12542)
    
    * fix: make sure log file has been closed and then remove the shutdown hook
    
    1. make sure log file has been closed and then remove the shutdown hook
    
    Signed-off-by: TheR1sing3un <[email protected]>
    
    * rerun
    
    * rerun
    
    ---------
    
    Signed-off-by: TheR1sing3un <[email protected]>
---
 .../apache/hudi/common/table/log/HoodieLogFormatWriter.java   | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git 
a/hudi-hadoop-common/src/main/java/org/apache/hudi/common/table/log/HoodieLogFormatWriter.java
 
b/hudi-hadoop-common/src/main/java/org/apache/hudi/common/table/log/HoodieLogFormatWriter.java
index 6b38e10f25c..5c4c141947d 100644
--- 
a/hudi-hadoop-common/src/main/java/org/apache/hudi/common/table/log/HoodieLogFormatWriter.java
+++ 
b/hudi-hadoop-common/src/main/java/org/apache/hudi/common/table/log/HoodieLogFormatWriter.java
@@ -231,10 +231,11 @@ public class HoodieLogFormatWriter implements 
HoodieLogFormat.Writer {
 
   @Override
   public void close() throws IOException {
+    closeStream();
+    // remove the shutdown hook after closing the stream to avoid memory leaks
     if (null != shutdownThread) {
       Runtime.getRuntime().removeShutdownHook(shutdownThread);
     }
-    closeStream();
   }
 
   private void closeStream() throws IOException {
@@ -275,12 +276,10 @@ public class HoodieLogFormatWriter implements 
HoodieLogFormat.Writer {
     shutdownThread = new Thread() {
       public void run() {
         try {
-          LOG.warn("running logformatwriter hook");
-          if (output != null) {
-            closeStream();
-          }
+          LOG.warn("running HoodieLogFormatWriter shutdown hook to close 
output stream for log file: {}", logFile);
+          closeStream();
         } catch (Exception e) {
-          LOG.warn(String.format("unable to close output stream for log file 
%s", logFile), e);
+          LOG.warn("unable to close output stream for log file: {}", logFile, 
e);
           // fail silently for any sort of exception
         }
       }

Reply via email to