Skip to content

Commit 9fc3cc8

Browse files
committed
fix(write-queue): close fd
1 parent 6b1a994 commit 9fc3cc8

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

src/download/download-engine/streams/download-engine-write-stream/download-engine-write-stream-nodejs.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,14 +153,17 @@ export default class DownloadEngineWriteStreamNodejs extends BaseDownloadEngineW
153153
return JSON.parse(metadataString);
154154
} catch { }
155155
} finally {
156-
await this.close();
156+
await this._closeFd();
157157
}
158158
}
159159

160160
override async close() {
161161
this._writeQueue.close();
162162
await this._writeQueue.drain();
163+
await this._closeFd();
164+
}
163165

166+
private async _closeFd(){
164167
if (!this._fd) {
165168
return;
166169
}

src/download/download-engine/streams/download-engine-write-stream/utils/WriteQueue.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { FileHandle } from "fs/promises";
2+
import WriterIsClosedError from "../errors/writer-is-closed-error.js";
23

34
const MIN_BUFFER_SIZE = 2 * 1024 * 1024; // 2 MB
45
const MAX_BUFFER_SIZE = 64 * 1024 * 1024; // 64 MB
@@ -57,7 +58,9 @@ export default class WriteQueue {
5758
* merges with adjacent regions, and flushes when threshold is exceeded.
5859
*/
5960
addWrite(cursor: number, buffers: Uint8Array[]): void | Promise<void> {
60-
if (this._closed) return;
61+
if (this._closed) {
62+
throw new WriterIsClosedError("Cannot add write to closed WriteQueue");
63+
}
6164

6265
const length = buffers.reduce((sum, buf) => sum + buf.length, 0);
6366

0 commit comments

Comments
 (0)