Stateless facade for FileSystemProvider SPI#895
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Register a stateless facade class via the
FileSystemProviderSPI. All instance of this facade class delegateto a singleton
SftpFileSystemProvider.Fixes #743.