Skip to content

Conversation

@tomaswolf
Copy link
Member

@tomaswolf tomaswolf commented Jan 5, 2026

Use a thread-safe SftpClient, serializing all writes for SFTP commands or data over a single SSH channel. If needed, re-create the channel (and SftpClient) if it gets closed by the server side.

As a result, an SftpFileSystem uses a single SSH channel.

Fixes #855.

Synchronize sending messages through the channel. Messages would be
synchronized at the connection level anyway, and most uses of SFTP will
be single-threaded anyway, so synchronizing on channel level should not
impact performance much.

With a thread-safe SftpClient, the use of SftpClients in the
SftpFileSystem can be simplified.
Drop the SftpClient pool and use a single thread-safe SftpClient per
SftpFileSystem. The SftpClient is closed when the file system is closed.
If the server side should close the channel, operations using this
client may fail, but a server should not close channels unless there is
no traffic. If a channel is closed by the server because it is idle, the
SftpFileSystem will re-create a new SftpClient, thus opening a new
channel, on the next operation.

It is possible that a server decides to close a previously idle channel
just in the moment the client-side wants to use that channel for a new
operation. The new operation would then fail. But this possibility has
always existed in all previous versions of the SftpFileSystem code.

The main advantage of using a single SftpClient is that all SFTP
operations are done in the same channel. This can be important with
servers that restrict the number of concurrently open channels per SSH
session.
@tomaswolf tomaswolf merged commit 4eccf49 into apache:master Jan 6, 2026
7 checks passed
@tomaswolf tomaswolf deleted the gh-855 branch January 6, 2026 20:18
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.

The custom sftp server was blocked while processing ls

1 participant