Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion packages/server/lib/serve/Supervisor.js
Original file line number Diff line number Diff line change
Expand Up @@ -560,8 +560,19 @@ class Supervisor extends EventEmitter {
this.#definitionWatcher = null;
this.#liveReloadHandle?.close();
this.#detachRelay();
this.#httpServer?.close(callback);
this.#clearRecoveryTimer();
// The callback fires only after every native handle is closed, not on socket close. The
// BuildServer's teardown closes the @parcel/watcher subscriptions and the node:sqlite handle
// (which maps a 256 MB region of the database into memory); a caller resuming while SQLite is
// mid-close raises an access violation on Windows (0xC0000005). So start the socket close here
// but await it last.
const httpClosed = new Promise((resolve) => {
if (!this.#httpServer) {
resolve();
return;
}
this.#httpServer.close(() => resolve());
});
try {
await definitionWatcher?.destroy();
} catch (err) {
Expand All @@ -572,6 +583,8 @@ class Supervisor extends EventEmitter {
} catch (err) {
log.verbose(`Error while destroying BuildServer: ${err?.message ?? err}`);
}
await httpClosed;
callback?.();
}
}

Expand Down
Loading