Skip to content

Commit c2dc7b8

Browse files
committed
refactor(project): Always close CacheManager in BuildServer destroy
The active build promise can reject (e.g. when Cache=Force detects a stale cache and throws). When destroy() awaited that promise, the throw skipped the closeCacheManager() call below, leaving the SQLite cache.db handle open. On Windows this caused subsequent tests to fail with EBUSY when fs.rm tried to remove the buildCache directory. Wrap the active-build await in try/finally so the cache manager is released even when the build rejected.
1 parent 8b9933b commit c2dc7b8

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

packages/project/lib/build/BuildServer.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,11 +155,17 @@ class BuildServer extends EventEmitter {
155155
this.#destroyed = true;
156156
clearTimeout(this.#processBuildRequestsTimeout);
157157
await this.#watchHandler.destroy();
158-
if (this.#activeBuild) {
159-
// Await active build to finish
160-
await this.#activeBuild;
158+
try {
159+
if (this.#activeBuild) {
160+
// Await active build to finish
161+
await this.#activeBuild;
162+
}
163+
} finally {
164+
// Always release the cache manager, even when the active build rejected
165+
// (e.g. Force-mode stale-cache errors). Otherwise the SQLite handle leaks
166+
// and subsequent fs.rm of the cache directory fails with EBUSY on Windows.
167+
this.#projectBuilder.closeCacheManager();
161168
}
162-
this.#projectBuilder.closeCacheManager();
163169
}
164170

165171
/**

0 commit comments

Comments
 (0)