Skip to content

Commit 697e3be

Browse files
committed
refactor(builder): Fix Windows test timeouts caused by leaked handles and missing error handler
Close CacheManager in a finally block within buildToTarget() so the SQLite database is released even when the build throws. Previously, builds that threw (e.g. SourceChangedDuringBuildError) leaked a refcount, keeping the DB memory-mapped on Windows and preventing cleanup by subsequent tests. Add an error event handler to the JSDoc child process spawn. Without it, a failed spawn on Windows would never emit close, hanging the promise indefinitely.
1 parent 63d5a97 commit 697e3be

3 files changed

Lines changed: 20 additions & 14 deletions

File tree

packages/builder/lib/processors/jsdoc/jsdocGenerator.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,11 @@ async function buildJsdoc({sourcePath, configPath}) {
163163
"--verbose",
164164
sourcePath
165165
];
166-
const exitCode = await new Promise((resolve /* , reject */) => {
166+
const exitCode = await new Promise((resolve, reject) => {
167167
const child = spawn("node", args, {
168168
stdio: ["ignore", "ignore", "inherit"]
169169
});
170+
child.on("error", reject);
170171
child.on("close", resolve);
171172
});
172173

packages/builder/test/lib/processors/jsdoc/jsdocGenerator.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,9 @@ test.serial("buildJsdoc", async (t) => {
8080
let exitCode = 0;
8181
const cpStub = sinon.stub().returns({
8282
on: (event, callback) => {
83-
callback(exitCode);
83+
if (event === "close") {
84+
callback(exitCode);
85+
}
8486
}
8587
});
8688

packages/project/lib/build/ProjectBuilder.js

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -217,18 +217,21 @@ class ProjectBuilder {
217217
});
218218
}
219219
const pWrites = [];
220-
await this.#build(requestedProjects, async (projectName, project, projectBuildContext) => {
221-
if (!fsTarget) {
222-
// Nothing to write to
223-
return;
224-
}
225-
// Only write requested projects to target
226-
// (excluding dependencies that were required to be built, but not requested)
227-
this.#log.verbose(`Writing out files for project ${projectName}...`);
228-
await this._writeResults(projectBuildContext, fsTarget, pWrites);
229-
});
230-
await Promise.all(pWrites);
231-
this._buildContext.closeCacheManager();
220+
try {
221+
await this.#build(requestedProjects, async (projectName, project, projectBuildContext) => {
222+
if (!fsTarget) {
223+
// Nothing to write to
224+
return;
225+
}
226+
// Only write requested projects to target
227+
// (excluding dependencies that were required to be built, but not requested)
228+
this.#log.verbose(`Writing out files for project ${projectName}...`);
229+
await this._writeResults(projectBuildContext, fsTarget, pWrites);
230+
});
231+
await Promise.all(pWrites);
232+
} finally {
233+
this._buildContext.closeCacheManager();
234+
}
232235
}
233236

234237
/**

0 commit comments

Comments
 (0)