Skip to content

Commit dfef70f

Browse files
committed
fix(dev): track cold forks in the pool so shutdown reaps them
1 parent 1897968 commit dfef70f

2 files changed

Lines changed: 13 additions & 0 deletions

File tree

packages/nuxt-cli/src/dev/pool.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ export class ForkPool {
9999
// No forks in pool, create a cold fork
100100
debug('No pre-warmed forks available, starting cold fork')
101101
const coldFork = this.createFork()
102+
this.pool.push(coldFork)
102103
await coldFork.ready
103104
coldFork.state = 'active'
104105
if (onMessage) {

packages/nuxt-cli/test/unit/fork-pool.spec.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,18 @@ describe('forkPool', () => {
3535
expect(pool.getStats().total).toBe(1)
3636
})
3737

38+
it('should reap a cold fork on shutdown', { timeout: 30_000 }, async () => {
39+
const pool = createPool(0)
40+
await pool.getFork({ cwd: '/some/project', args: {} })
41+
expect(pool.getStats()).toMatchObject({ total: 1, active: 1 })
42+
43+
const [child] = (pool as unknown as { pool: Array<{ process: ChildProcess }> }).pool.map(f => f.process)
44+
;(pool as unknown as { killAll: (signal: number) => void }).killAll(0)
45+
await vi.waitFor(() => {
46+
expect(child!.killed).toBe(true)
47+
}, { timeout: 10_000, interval: 25 })
48+
})
49+
3850
it('should kill every fork on shutdown', { timeout: 30_000 }, async () => {
3951
const pool = createPool(3)
4052
pool.startWarming()

0 commit comments

Comments
 (0)