Skip to content

Stateless facade for FileSystemProvider SPI#895

Merged
tomaswolf merged 2 commits into
apache:masterfrom
tomaswolf:gh-743
Apr 25, 2026
Merged

Stateless facade for FileSystemProvider SPI#895
tomaswolf merged 2 commits into
apache:masterfrom
tomaswolf:gh-743

Conversation

@tomaswolf

Copy link
Copy Markdown
Member

Register a stateless facade class via the FileSystemProvider SPI. All instance of this facade class delegate
to a singleton SftpFileSystemProvider.

Fixes #743.

See [1]. Apache MINA SSHD never had that problem, but we also had no
test for this. So add one just to be sure.

[1] https://bugzilla.mindrot.org/show_bug.cgi?id=3950
…oader

When SFTP file systems are created through the standard Java mechanism
via java.nio.file.FileSystems.newFileSystem(URI, Map, Classloader), the
JDK uses the ServiceLoader to find registered file system providers.
It remembers any it can find via the system classloader or via the
platform classloader as "installed providers" and creates only exactly
one instance of them.

When it cannot find a provider matching the URI scheme in the
"installed providers" and a classloader is given, it then tries to
find a matching file system provider using that classloader. The
ServiceLoader instantiates each provider it finds to check its scheme
against the URI scheme. But it doesn't remember these file system
providers, so if FileSystems.newFileSystem() is called again, another
instance of SftpFileSystemProvider got created.

When the returned file system is used, the SftpFileSystemProvider
creates an SshClient, and an I/O thread pool is set up. If multiple
SftpFileSystemProviders get created, there will also be multiple
SshClients, and multiple thread pools.

Avoid this by registering via the FileSystemProvider SPI only a
stateless facade class. All instance of this facade class delegate
to a singleton SftpFileSystemProvider.
@tomaswolf tomaswolf changed the title Gh 743 Stateless facade for FileSystemProvider SPI Apr 25, 2026
@tomaswolf tomaswolf merged commit 1285419 into apache:master Apr 25, 2026
7 checks passed
@tomaswolf tomaswolf deleted the gh-743 branch April 25, 2026 21:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Threads leak when running from Executable Jar

1 participant