NianticRyan commented on issue #24098:
URL: https://github.com/apache/beam/issues/24098#issuecomment-1311182924

   I did some more digging into the code. I believe this is a bug with the code 
in commit posted above.
   The ScanReport needs to be closed before we return from the function or else 
the file descriptors are left open.
   
   I cloned the repo and published my own version of the package with this 
code, and I'm not seeing the fd leaks anymore.
   
   This wasn't an issue prior to 2.36 because as I noted in the original post, 
the code from 2.35 and lower does not do a full scan. It just generates a 
placeholder `ScanResult` with the classpath. A full scan actually goes in and 
opens every file and thus, the ScanReport needs to be closed after it is done - 
else we are left with unclosed fds. See this 
[link](https://github.com/classgraph/classgraph/blob/latest/src/main/java/io/github/classgraph/ClassGraph.java#L1563)
 in the docs of classgraph.
   Will publish a PR with this fix soon.
   
   ```
     @Override
     public List<String> detect(ClassLoader classLoader) {
       ScanResult scanResult =  classGraph
               .disableNestedJarScanning()
               .addClassLoader(classLoader)
               .scan(1);
       List<File> classpathContents = scanResult.getClasspathFiles();
       scanResult.close();
   
       return 
classpathContents.stream().map(File::getAbsolutePath).collect(Collectors.toList());
     }
   ```


-- 
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