Skip to content

Commit aea7e1c

Browse files
committed
fix(disk): force streams to close
1 parent 3e6959e commit aea7e1c

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

packages/core/src/storages/disk-storage.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,13 @@ export class DiskStorage extends BaseStorage<DiskFile> {
147147
const lengthChecker = streamLength(part.contentLength || part.size - part.start);
148148
const checksumChecker = streamChecksum(part.checksum, part.checksumAlgorithm);
149149
const keepPartial = !part.checksum;
150-
const failWithCode = (code?: ERRORS): void => {
150+
const cleanupStreams = (): void => {
151151
dest.close();
152+
lengthChecker.destroy();
153+
checksumChecker.destroy();
154+
};
155+
const failWithCode = (code?: ERRORS): void => {
156+
cleanupStreams();
152157
resolve([NaN, code]);
153158
};
154159
lengthChecker.on('error', () => failWithCode(ERRORS.FILE_CONFLICT));
@@ -158,7 +163,10 @@ export class DiskStorage extends BaseStorage<DiskFile> {
158163
.pipe(lengthChecker)
159164
.pipe(checksumChecker)
160165
.pipe(dest)
161-
.on('error', reject)
166+
.on('error', (err?: unknown): void => {
167+
cleanupStreams();
168+
reject(err);
169+
})
162170
.on('finish', () => {
163171
return resolve([part.start + dest.bytesWritten]);
164172
});

0 commit comments

Comments
 (0)