Skip to content

Commit f1e501a

Browse files
committed
fix: ssg on windows
1 parent cc6ae9d commit f1e501a

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

packages/qwik-city/src/static/node/node-main.ts

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export async function createNodeMainProcess(sys: System, opts: StaticGenerateOpt
1818
const ssgWorkers: StaticGeneratorWorker[] = [];
1919
const sitemapBuffer: string[] = [];
2020
let sitemapPromise: Promise<any> | null = null;
21-
21+
let hasExited = false;
2222
opts = { ...opts };
2323

2424
let outDir = opts.outDir;
@@ -103,7 +103,17 @@ export async function createNodeMainProcess(sys: System, opts: StaticGenerateOpt
103103
terminateResolve = resolve;
104104
nodeWorker.postMessage(msg);
105105
});
106-
await nodeWorker.terminate();
106+
// Wait for worker to exit naturally (it calls process.exit(0) after close)
107+
// If it doesn't exit in time, force terminate
108+
const maxWaitMs = 1000;
109+
const startTime = Date.now();
110+
while (!hasExited && Date.now() - startTime < maxWaitMs) {
111+
await new Promise((resolve) => setTimeout(resolve, 50));
112+
}
113+
114+
if (!hasExited) {
115+
await nodeWorker.terminate();
116+
}
107117
},
108118
};
109119

@@ -133,6 +143,7 @@ export async function createNodeMainProcess(sys: System, opts: StaticGenerateOpt
133143
});
134144

135145
nodeWorker.on('exit', (code) => {
146+
hasExited = true;
136147
if (code !== 0) {
137148
console.error(`worker exit ${code}`);
138149
}
@@ -187,9 +198,15 @@ export async function createNodeMainProcess(sys: System, opts: StaticGenerateOpt
187198
console.error(e);
188199
}
189200
}
190-
ssgWorkers.length = 0;
191201

192202
await Promise.all(promises);
203+
ssgWorkers.length = 0;
204+
205+
// On Windows, give extra time for all workers to fully exit
206+
// This prevents resource conflicts in back-to-back builds
207+
if (process.platform === 'win32') {
208+
await new Promise((resolve) => setTimeout(resolve, 300));
209+
}
193210
};
194211

195212
if (sitemapOutFile) {
@@ -202,6 +219,10 @@ export async function createNodeMainProcess(sys: System, opts: StaticGenerateOpt
202219

203220
for (let i = 0; i < maxWorkers; i++) {
204221
ssgWorkers.push(createWorker());
222+
// On Windows, add delay between worker creation to avoid resource contention
223+
if (process.platform === 'win32' && i < maxWorkers - 1) {
224+
await new Promise((resolve) => setTimeout(resolve, 100));
225+
}
205226
}
206227

207228
const mainCtx: MainContext = {

0 commit comments

Comments
 (0)