fix(run-log-store): close fd leak in log append that caused spawn EBADF
The append method created a new WriteStream for every log chunk and resolved the promise on the end callback (data flushed) rather than the close event (fd released). Over many agent runs the leaked fds corrupted the fd table, causing child_process.spawn to fail with EBADF. Replace with fs.appendFile which properly opens, writes, and closes the fd before resolving. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import { createReadStream, createWriteStream, promises as fs } from "node:fs";
|
import { createReadStream, promises as fs } from "node:fs";
|
||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
import { createHash } from "node:crypto";
|
import { createHash } from "node:crypto";
|
||||||
import { notFound } from "../errors.js";
|
import { notFound } from "../errors.js";
|
||||||
@@ -113,11 +113,7 @@ function createLocalFileRunLogStore(basePath: string): RunLogStore {
|
|||||||
stream: event.stream,
|
stream: event.stream,
|
||||||
chunk: event.chunk,
|
chunk: event.chunk,
|
||||||
});
|
});
|
||||||
await new Promise<void>((resolve, reject) => {
|
await fs.appendFile(absPath, `${line}\n`, "utf8");
|
||||||
const stream = createWriteStream(absPath, { flags: "a", encoding: "utf8" });
|
|
||||||
stream.on("error", reject);
|
|
||||||
stream.end(`${line}\n`, () => resolve());
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
|
|
||||||
async finalize(handle) {
|
async finalize(handle) {
|
||||||
|
|||||||
Reference in New Issue
Block a user