mscdex / ssh2-streams

SSH2 and SFTP client/server protocol streams for node.js
MIT License
204 stars 143 forks source link

"Missing file segements in upload" error when using Fast Put #171

Open scooper91 opened 3 years ago

scooper91 commented 3 years ago

Hi,

We're frequently seeing a Missing file segements in upload:0 error when trying to upload a file to a client's SFTP. It's a large file - ~1GB. The upload is successful and complete (we've verified the checksum), so we're unsure why we're seeing this error. We seeing this error about 80% of the time.

We found this issue on the library we're using. We also tried using a different library (which still uses this ssh2-streams library), but got the same error. We are able to successfully upload a file using scp.

We enabled debug mode, but nothing really jumped out. We did notice a 2 second pause between the last debug log and when the error was thrown.

Here's a screenshot of when the error was thrown:

image (9)

We're not sure whether this is a problem with the SFTP server, or an issue at our end.

Any advice would be greatly appreciated.

Thanks!

mscdex commented 3 years ago

That error is not coming from this module, so I can't help you there. You'll need to take it up with ssh2-sftp-client it seems.

scooper91 commented 3 years ago

Thanks for the reply.

The error is surfacing through the ssh2-sftp-client, but at the bottom of the stack, the error is coming from ssh2-streams. In the linked issue from the ssh2-sftp-client, the maintainer says it's not to do with their library. As I mentioned, we got the same error (with the stack originating from this ssh2-streams library) using a different library.

It looks like the ssh2-sftp-client library is calling fastPut in this library, and the error in the stack trace is just a formatted version of the underlying error from ssh2-streams.

Thanks!

mscdex commented 3 years ago

Then I can only guess it's coming from the server because this module has never had an error message like that before. Is this a custom/specialty/uncommon sftp/ssh server?

scooper91 commented 3 years ago

It appears that we weren't doing a diligent enough check to ensure the files were uploading correctly. The file size is always correct when uploading the files, even when we get the error, but the start of the file is corrupted. We get a bunch of null characters (which show as ^@ in Vim), which represents zero-bytes.

e.g. When opening one of the files in Vim, it looks something like this (but with a lot more zero-byte characters)

@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@rest-of-the-data

Unfortunately, it's a third-party SFTP, which we're just integrating with, so we don't know much about it! We do not appear to have an issue when using SCP to upload files, and the owner of the SFTP has used FileZilla without any issues (although I don't know if they upload the file chunks concurrently).

mscdex commented 3 years ago

Does the upload work when using sftp.createWriteStream() instead? That function does not send concurrent chunks.