[VFS] Questions about VFS SFTP Session Management

w blabla <[email protected]> Thu, 24 Jul 2025 17:07:16 +0800
Newsgroups gmane.comp.jakarta.commons.user
Message-ID <[email protected]>
--Apple-Mail=_0BE3610F-A4BF-409B-84C7-201E84FBFFEB
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain;
	charset=utf-8

Hi,
I have a few questions regarding how VFS=E2=80=99s =
StandardFileSystemManager manages SFTP sessions.

In my usage, I noticed that after a file transfer is completed, the =
session is not actively closed, and corresponding sshd processes remain =
on the SFTP server.

I am using VFS in a service with 5 StandardFileSystemManager instances, =
each handling a large number of concurrent upload tasks.

During local testing, when concurrency is high (e.g., 100), most =
server-side processes are cleaned up, with only a few residual =
SSH-related processes. However, in our production environment, we =
observe a large number of lingering server-side processes.



Eventually, I found that SftpFileSystem#doCloseCommunicationLink is =
responsible for closing the session.

I also noticed that explicitly calling FileSystemManager#closeFileSystem =
does close the session, but it carries potential risks. Another =
alternative I found is to call =
DefaultFileSystemManager#freeUnusedResources. And it worked.



Here are my questions:

Do we have to close the session manually now? If it is supposed to be =
automatic, how does the mechanism work, and why aren=E2=80=99t the =
sessions being closed?

If manual intervention is required, should we set =
standardFileSystemManager.setFilesCache(new WeakRefFilesCache()) (to =
help with quicker resource release), and then periodically call =
DefaultFileSystemManager#freeUnusedResources()?

In the case of SoftRefFilesCache, I see a log that says =E2=80=9CClose =
FileSystem=E2=80=9D =E2=80=94 does this merely release the association, =
or does it actually close the FileSystem?



The code is:

private StandardFileSystemManager fileSystemManager;

  public FileClient() throws FileSystemException {
    this.fileSystemManager =3D new StandardFileSystemManager();
    this.fileSystemManager.init();
  }

  private <T> T execute(String path, Function<FileObject, T> function) =
throws FileSystemException {
    FileSystemOptions fileSystemOptions =3D this.genOptions();
    try {
      FileObject fileObject =3D fileSystemManager.resolveFile(path, =
fileSystemOptions);
      try {
        return function.apply(fileObject);
      } finally {
        fileObject.close();
//          manager.closeFileSystem(fileObject.getFileSystem());
      }
    } catch (Exception e) {
      throw new RuntimeException(e);
    }
  }

  public boolean upload(String path, InputStream inputStream) throws =
FileSystemException {
    return execute(path, (fileObject) -> {
      long startTime =3D YqgClock.now();
      long total;
      try (FileContent fileContent =3D fileObject.getContent();
           OutputStream outputStream =3D fileContent.getOutputStream()) =
{
        total =3D IOUtils.copy(inputStream, outputStream);
      } catch (IOException e) {
        throw new RuntimeException(e);
      }
      return true;
    });
  }

Thanks!

--Apple-Mail=_0BE3610F-A4BF-409B-84C7-201E84FBFFEB--