Skip to content

lock SendData to fix random connection failures #1623

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 29, 2025

Conversation

mus65
Copy link
Contributor

@mus65 mus65 commented Mar 29, 2025

Fixes #1253 and probably #1493 .

This adds a lock to SendData to avoid the loop to interleave between multiple messages, causing a "bad message" error in the server (see #1253 (comment)).

This may totally be the wrong fix since I'm not really familiar with the protocol and I couldn't find anything specifically about this in the RFCs. But it seems sensible to me that the server doesn't expect this to happen.

By adding some logging I confirmed that in the failure cases of the test, the loop did indeed interleave between different messages. In the success cases, there simply were never more than 1 iteration, so it couldn't interleave.

Without this fix, I had the test fail about every third run. With this fix, I have run the test for about 500 times without a failure.

@Rob-Hague
Copy link
Collaborator

Nice! It makes sense: the SFTP layer has its own length-prefixed packets so when they are being (wrongly) split up in the channel layer, the server reads an SFTP packet, tries to read the length of the next SFTP packet but ends up reading some random bytes in the middle of a different packet. Good find

@Rob-Hague Rob-Hague merged commit c318e39 into sshnet:develop Mar 29, 2025
4 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.

Unstable integration test Test_Sftp_Multiple_Async_Upload_And_Download_10Files_5MB_Each
2 participants