pitrou commented on issue #43867:
URL: https://github.com/apache/arrow/issues/43867#issuecomment-2316890607

   It looks like the `OrcReader` class currently relies on `try {}` for proper 
resource management, other resource deletion (destruction of C++ Orc reader 
instances) is deferred to process shutdown when it might be too late.
   
   Perhaps try something like this:
   ```diff
   diff --git 
a/java/adapter/orc/src/main/java/org/apache/arrow/adapter/orc/OrcReader.java 
b/java/adapter/orc/src/main/java/org/apache/arrow/adapter/orc/OrcReader.java
   index ca9b44e7e8..ab0510092b 100644
   --- 
a/java/adapter/orc/src/main/java/org/apache/arrow/adapter/orc/OrcReader.java
   +++ 
b/java/adapter/orc/src/main/java/org/apache/arrow/adapter/orc/OrcReader.java
   @@ -17,6 +17,7 @@
    package org.apache.arrow.adapter.orc;
    
    import java.io.IOException;
   +import java.lang.ref.Cleaner;
    import org.apache.arrow.memory.BufferAllocator;
    import org.apache.arrow.vector.ipc.ArrowReader;
    
   @@ -26,7 +27,9 @@ import org.apache.arrow.vector.ipc.ArrowReader;
     * ArrowReader.
     */
    public class OrcReader implements AutoCloseable {
   -  private final OrcReaderJniWrapper jniWrapper;
   +  private static final OrcReaderJniWrapper jniWrapper = 
OrcReaderJniWrapper.getInstance();
   +  private static final Cleaner cleaner = Cleaner.create();
   +
      private BufferAllocator allocator;
    
      /** reference to native reader instance. */
   @@ -44,6 +47,12 @@ public class OrcReader implements AutoCloseable {
        this.allocator = allocator;
        this.jniWrapper = OrcReaderJniWrapper.getInstance();
        this.nativeInstanceId = jniWrapper.open(filePath);
   +    registerCleaner(this, jniWrapper, nativeInstanceId);
   +  }
   +
   +  private static void registerCleaner(Object instance, OrcReaderJniWrapper 
jniWrapper,
   +                                      long nativeInstanceId) {
   +    cleaner.register(instance, () -> jniWrapper.close(nativeInstanceId));
      }
    
      /**
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to