Skip to content

Commit 4538067

Browse files
committed
fix(dev): do not end the dev session when a replaced fork exits non-zero
1 parent ec6b08a commit 4538067

2 files changed

Lines changed: 17 additions & 0 deletions

File tree

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,9 @@ export class ForkPool {
244244
privatekillFork(fork: PooledFork,signal: NodeJS.Signals|number='SIGTERM'): Promise<void>{
245245
constwasAlive=fork.state!=='dead'&&!!fork.process&&fork.process.exitCode===null
246246
fork.state='dead'
247+
// A fork we are shutting down on purpose must not end the session, however
248+
// it exits on the way out.
249+
fork.serving=false
247250
if(fork.process){
248251
// signal 0 only probes for liveness, so map the `exit` case onto a real signal
249252
fork.process.kill(signal===0 ? 'SIGTERM' : signal)

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,20 @@ describe('fork pool', () => {
9191
exit.mockRestore()
9292
})
9393

94+
it('should not end the session when the serving fork is closed deliberately',async()=>{
95+
constexit=vi.spyOn(process,'exit').mockImplementation(()=>undefinedasnever)
96+
constactive=awaitcreatePool().getFork(context)
97+
active.promote()
98+
99+
constchild=forks.find(f=>f.pid===active.pid)!
100+
constclosing=active.close()
101+
child.emit('close',1,null)
102+
awaitclosing
103+
104+
expect(exit).not.toHaveBeenCalled()
105+
exit.mockRestore()
106+
})
107+
94108
it('should reject when the fork exits before it starts',async()=>{
95109
fork.mockImplementation(()=>{
96110
constchild=newFakeFork()

0 commit comments

Comments
 (0)