Fix uploader API to handle write stream errors

When the upload is aborted/abandoed because the source file is missing,
the write stream is never destroyed. This dangling write stream can
later error and cause a crash.

Instead, create the write stream on demand and nearer to pipeline() to
make sure we do 'error' handling.
This commit is contained in:
Girish Ramakrishnan
2026-01-20 22:22:02 +01:00
parent 944f163882
commit 42cefd56eb
6 changed files with 36 additions and 30 deletions

View File

@@ -54,14 +54,16 @@ async function addFile(sourceFile, encryption, uploader, progressCallback) {
progressCallback({ message: `Uploading ${sourceFile}: ${transferred}M@${speed}MBps` }); // 0M@0MBps looks wrong
});
// careful not to have async code between here and pipeline() for 'error' handling
const hash = new HashStream();
const destStream = uploader.createStream();
let pipeline = null;
if (encryption) {
const encryptStream = new EncryptStream(encryption);
pipeline = safe(stream.pipeline(sourceStream, encryptStream, ps, hash, uploader.stream));
pipeline = safe(stream.pipeline(sourceStream, encryptStream, ps, hash, destStream));
} else {
pipeline = safe(stream.pipeline(sourceStream, ps, hash, uploader.stream));
pipeline = safe(stream.pipeline(sourceStream, ps, hash, destStream));
}
const [error] = await safe(pipeline);

View File

@@ -146,16 +146,17 @@ async function tarPack(dataLayout, encryption, uploader, progressCallback) {
progressCallback({ message: `Uploading backup ${transferred}M@${speed}MBps` });
});
// careful not to have async code between here and pipeline() for 'error' handling
const pack = tar.pack();
const hash = new HashStream();
const destStream = uploader.createStream();
let pipeline = null;
if (encryption) {
const encryptStream = new EncryptStream(encryption);
pipeline = safe(stream.pipeline(pack, gzip, encryptStream, ps, hash, uploader.stream));
pipeline = safe(stream.pipeline(pack, gzip, encryptStream, ps, hash, destStream));
} else {
pipeline = safe(stream.pipeline(pack, gzip, ps, hash, uploader.stream));
pipeline = safe(stream.pipeline(pack, gzip, ps, hash, destStream));
}
let fileCount = 0;