GH-774: Fix WritePendingException#775
Merged
Merged
Conversation
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.
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.
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.