SFTP Missing finish event
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 5.8k
- Forks
- 734
- PR merge metrics
- No merged PRs in 30d
Description
It looks like SFTP write streams created with sftp.createWriteStream() may not be emitting a finish event. For example, with the following code
const ws = sftp.createWriteStream(`${config.sftpUrl}/stream-t3.txt`);
const rs = fs.createReadStream(`${config.localUrl}/test-file1.txt`);
ws.on('error', (err) => {
reject(err);
});
ws.on('finish', () => {
console.log('ws finish event fired');
resolve('Data streamed to remote file');
});
ws.on('close', () => {
console.log('ws close event fired');
})
rs.pipe(ws);
only a 'close' event is triggered. If we go the reverse direction, with a fs.createWriteStream() and an sftp.creatgeReadStream(), we get first a finish event and then a close event.
This is problematic if we want to use a write stream with autoClose: false as it means no event is emitted and we cannot tell when (for example) a pipe operation ahs completed (unless we watch for events on the reader of course, but that could cause issues with knowing when all buffered data has been flushed to the write stream etc).
This was observed using ssh2 v1.10.0 on Linux running Node 18.1.0.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the issue with sftp.createWriteStream(), fs.createReadStream(), and rs.pipe(ws) under the reported Node 18.1.0/Linux setup. Compare the close and finish events with autoClose enabled and disabled; done when the write stream reliably signals completion after all piped and buffered data has been flushed.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, node.js
- Domain
- backend, networking
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100