Skip to content

Commit f93bd1d

Browse files
committed
fix(dev): keep warming the pool once the app is served by a fork
1 parent dfef70f commit f93bd1d

2 files changed

Lines changed: 28 additions & 8 deletions

File tree

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

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ export class ForkPool {
6060
}
6161

6262
asyncgetFork(context: NuxtDevContext,onMessage?: (message: NuxtDevIPCMessage)=>void): Promise<()=>Promise<void>>{
63+
// Once the app is served by a fork, file changes are no longer visible to
64+
// this process, so a restart is the only signal left that more may follow.
65+
this.warming=true
66+
6367
// Try to get a ready fork from the pool
6468
constreadyFork=this.pool.find(f=>f.state==='ready')
6569

@@ -70,10 +74,7 @@ export class ForkPool {
7074
}
7175
awaitthis.sendContext(readyFork.process,context)
7276

73-
// Start warming a replacement fork
74-
if(this.warming){
75-
this.warmFork()
76-
}
77+
this.warmFork()
7778

7879
return()=>this.killFork(readyFork)
7980
}
@@ -88,10 +89,7 @@ export class ForkPool {
8889
}
8990
awaitthis.sendContext(warmingFork.process,context)
9091

91-
// Start warming a replacement fork
92-
if(this.warming){
93-
this.warmFork()
94-
}
92+
this.warmFork()
9593

9694
return()=>this.killFork(warmingFork)
9795
}
@@ -107,6 +105,8 @@ export class ForkPool {
107105
}
108106
awaitthis.sendContext(coldFork.process,context)
109107

108+
this.warmFork()
109+
110110
return()=>this.killFork(coldFork)
111111
}
112112

@@ -120,6 +120,11 @@ export class ForkPool {
120120
}
121121

122122
privatewarmFork(): void{
123+
constidle=this.pool.filter(f=>f.state==='warming'||f.state==='ready').length
124+
if(idle>=this.poolSize){
125+
return
126+
}
127+
123128
constfork=this.createFork()
124129
fork.ready.then(()=>{
125130
if(fork.state==='warming'){

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,21 @@ describe('forkPool', () => {
4747
},{timeout: 10_000,interval: 25})
4848
})
4949

50+
it('should keep the pool warm after handing out a fork',{timeout: 30_000},async()=>{
51+
constpool=createPool()
52+
awaitpool.getFork({cwd: '/some/project',args: {}})
53+
awaitwaitForReady(pool,1)
54+
expect(pool.getStats().active).toBe(1)
55+
})
56+
57+
it('should never warm a fork when the pool is disabled',{timeout: 30_000},async()=>{
58+
constpool=createPool(0)
59+
pool.startWarming()
60+
awaitpool.getFork({cwd: '/some/project',args: {}})
61+
awaitnewPromise(resolve=>setTimeout(resolve,1000))
62+
expect(pool.getStats()).toMatchObject({total: 1,active: 1,ready: 0,warming: 0})
63+
})
64+
5065
it('should kill every fork on shutdown',{timeout: 30_000},async()=>{
5166
constpool=createPool(3)
5267
pool.startWarming()

0 commit comments

Comments
 (0)