Skip to content

Commit

Permalink
fix(disk): force streams to close
Browse files Browse the repository at this point in the history
  • Loading branch information
kukhariev committed Dec 6, 2024
1 parent 3e6959e commit aea7e1c
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions packages/core/src/storages/disk-storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,13 @@ export class DiskStorage extends BaseStorage<DiskFile> {
const lengthChecker = streamLength(part.contentLength || part.size - part.start);
const checksumChecker = streamChecksum(part.checksum, part.checksumAlgorithm);
const keepPartial = !part.checksum;
const failWithCode = (code?: ERRORS): void => {
const cleanupStreams = (): void => {
dest.close();
lengthChecker.destroy();
checksumChecker.destroy();
};
const failWithCode = (code?: ERRORS): void => {
cleanupStreams();
resolve([NaN, code]);
};
lengthChecker.on('error', () => failWithCode(ERRORS.FILE_CONFLICT));
Expand All @@ -158,7 +163,10 @@ export class DiskStorage extends BaseStorage<DiskFile> {
.pipe(lengthChecker)
.pipe(checksumChecker)
.pipe(dest)
.on('error', reject)
.on('error', (err?: unknown): void => {
cleanupStreams();
reject(err);
})
.on('finish', () => {
return resolve([part.start + dest.bytesWritten]);
});
Expand Down

0 comments on commit aea7e1c

Please sign in to comment.