detective0922 opened a new issue, #500:
URL: https://github.com/apache/mina-sshd/issues/500

   ### Version
   
   V2.8.0
   
   ### Bug description
   
   I checked the https://github.com/apache/mina-sshd/issues/294 and merge the 
fix code to V2.8.0
   That fixed the old issue, but there is still a issue here.
   If a exception happen in FilterInputStream init, for example, a "No such 
file" exception happen in init of FilterInputStream
   `return new FilterInputStream(client.read(p.toString(), modes))  `
   then it will not call the "client.close()", so SftpClient will not close and 
keep increasing, finally lead to a OOM
   
   2024-05-11 12:00:02,311 INFO [LoggerStream] - SFTP error 
(SSH_FX_NO_SUCH_FILE): No such file
   2024-05-11 12:00:02,311 INFO [LoggerStream] -   at 
org.apache.sshd.sftp.client.impl.AbstractSftpClient.throwStatusException(AbstractSftpClient.java:217)
   2024-05-11 12:00:02,311 INFO [LoggerStream] -   at 
org.apache.sshd.sftp.client.impl.AbstractSftpClient.checkAttributesResponse(AbstractSftpClient.java:306)
   2024-05-11 12:00:02,311 INFO [LoggerStream] -   at 
org.apache.sshd.sftp.client.impl.AbstractSftpClient.checkAttributes(AbstractSftpClient.java:284)
   2024-05-11 12:00:02,311 INFO [LoggerStream] -   at 
org.apache.sshd.sftp.client.impl.AbstractSftpClient.stat(AbstractSftpClient.java:1001)
   2024-05-11 12:00:02,311 INFO [LoggerStream] -   at 
org.apache.sshd.sftp.client.impl.SftpInputStreamAsync.<init>(SftpInputStreamAsync.java:69)
   2024-05-11 12:00:02,311 INFO [LoggerStream] -   at 
org.apache.sshd.sftp.client.impl.AbstractSftpClient.read(AbstractSftpClient.java:1189)
   2024-05-11 12:00:02,311 INFO [LoggerStream] -   at 
org.apache.sshd.sftp.client.fs.SftpFileSystem$Wrapper.read(SftpFileSystem.java:491)
   2024-05-11 12:00:02,311 INFO [LoggerStream] -   at 
org.apache.sshd.sftp.client.fs.SftpFileSystem$Wrapper.read(SftpFileSystem.java:483)
   2024-05-11 12:00:02,311 INFO [LoggerStream] -   at 
org.apache.sshd.sftp.client.fs.SftpFileSystemProvider.newInputStream(SftpFileSystemProvider.java:525)
   2024-05-11 12:00:02,311 INFO [LoggerStream] -   at 
java.nio.file.Files.newInputStream(Files.java:152)
   
   
   ```
       @Override
       public InputStream newInputStream(Path path, OpenOption... options) 
throws IOException {
           Collection<OpenMode> modes = 
OpenMode.fromOpenOptions(Arrays.asList(options));
           if (modes.isEmpty()) {
               modes = EnumSet.of(OpenMode.Read);
           }
           SftpPath p = toSftpPath(path);
           //return p.getFileSystem().getClient().read(p.toString(), modes);
           SftpClient client = p.getFileSystem().getClient();
           return new FilterInputStream(client.read(p.toString(), modes)) { 
//line 525
               @Override
               public void close() throws IOException {
                   try {
                       super.close();
                   } finally {
                       client.close();
                   }
               }
           };
       }
   
   ```
   
   
   ### Actual behavior
   
   Memory leak happen
   
   ### Expected behavior
   
   No Memory Leak
   
   ### Relevant log output
   
   _No response_
   
   ### Other information
   
   _No response_


-- 
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: dev-unsubscr...@mina.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@mina.apache.org
For additional commands, e-mail: dev-h...@mina.apache.org

Reply via email to