Skip to content

GH-774: Fix WritePendingException#775

Merged
tomaswolf merged 1 commit into
apache:masterfrom
tomaswolf:gh-774
Jul 19, 2025
Merged

GH-774: Fix WritePendingException#775
tomaswolf merged 1 commit into
apache:masterfrom
tomaswolf:gh-774

Conversation

@tomaswolf
Copy link
Copy Markdown
Member

@tomaswolf tomaswolf commented Jul 19, 2025

If an SFTP file copy the twin buffering in SftpOutputStreamAsync may lead to it reading from the InputStream before the last buffer has been written. If the InputStream is an SftpInputStreamAsync and has no buffered data, it may also send SFTP messages to request more data. If both streams use the same SftpClient and thus the same SSH channel, this may lead to the input stream writing its "more data" request before the output stream has completed its write, causing the WritePendingException.

Fix this by ensuring that DefaultSftpClient.write() waits for the last write before doing a new write. This keeps the benefits of the twin buffer in SftpOututStreamAsync (it still can read ahead most of the time while a buffer is written) and at the same time ensures that other SFTP messages don't step on an asynchronous buffer write.

Fixes #774.

If an SFTP file copy the twin buffering in SftpOutputStreamAsync may
lead to it reading from the InputStream before the last buffer has
been written. If the InputStream is an SftpInputStreamAsync and has
no buffered data, it may also send SFTP messages to request more data.
If both streams use the same SftpClient and thus the same SSH channel,
this may lead to the input stream writing its "more data" request
before the output stream has completed its write, causing the
WritePendingException.

Fix this by ensuring that DefaultSftpClient.write() waits for the last
write before doing a new write. This keeps the benefits of the twin
buffer in SftpOututStreamAsync (it still can read ahead most of the
time while a buffer is written) and at the same time ensures that other
SFTP messages don't step on an asynchronous buffer write.
@tomaswolf tomaswolf merged commit c506d1e into apache:master Jul 19, 2025
7 checks passed
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.

WritePendingException when writing file

1 participant