Skip to content

Commit

Permalink
fix(nitro): handle terminating uninitialized worker
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Oct 22, 2021
1 parent 7797383 commit 9132a67
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/server/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,11 @@ function initWorker (filename): Promise<NitroWorker> {
})
}

async function killWorker (worker: NitroWorker) {
await worker.worker.terminate()
async function killWorker (worker?: NitroWorker) {
if (!worker) {
return
}
await worker.worker?.terminate()
worker.worker = null
if (worker.address && existsSync(worker.address)) {
await fsp.rm(worker.address).catch(() => {})
Expand All @@ -62,9 +65,7 @@ export function createDevServer (nitroContext: NitroContext) {
const newWorker = await initWorker(workerEntry)

// Kill old worker in background
if (currentWorker) {
killWorker(currentWorker).catch(err => console.error(err))
}
killWorker(currentWorker).catch(err => console.error(err))

// Replace new worker as current
currentWorker = newWorker
Expand Down Expand Up @@ -136,9 +137,7 @@ export function createDevServer (nitroContext: NitroContext) {
if (watcher) {
await watcher.close()
}
if (currentWorker) {
await killWorker(currentWorker)
}
await killWorker(currentWorker)
await Promise.all(listeners.map(l => l.close()))
listeners = []
}
Expand Down

0 comments on commit 9132a67

Please sign in to comment.