@@ -197,7 +197,6 @@ const command = defineCommand({
197197 } )
198198
199199 // On hard restart, use a fork from the pool
200- let cleanupCurrentFork : ( ( ) => Promise < void > ) | undefined
201200 // Whatever is serving the app right now: this process, then each fork in turn.
202201 let closeCurrent = close
203202 let currentPid = process . pid
@@ -255,8 +254,9 @@ const command = defineCommand({
255254 : undefined ,
256255 onMessage : ( message ) => {
257256 // Handle IPC messages from the fork
258- if ( message . type === 'nuxt:internal:dev:ready' ) {
259- if ( startTime ) {
257+ if ( message . type === 'nuxt:internal:dev:ready' || message . type === 'nuxt:internal:dev:loading:error' ) {
258+ serving = true
259+ if ( message . type === 'nuxt:internal:dev:ready' && startTime ) {
260260 debug ( `Dev server ready for connections in ${ Date . now ( ) - startTime } ms` )
261261 }
262262 }
@@ -278,19 +278,20 @@ const command = defineCommand({
278278 catch ( error ) {
279279 await fork ?. close ( )
280280 const detail = error instanceof Error ? error . message : String ( error )
281- logger . error ( handover
282- ? `Could not restart the dev server, keeping the current one: ${ detail } `
283- : `Could not restart the dev server: ${ detail } ` )
284- if ( handover ) {
285- onRestart ( restart )
281+ if ( ! handover ) {
282+ // The outgoing server is already closed, so there is nothing left to
283+ // serve the app and no watcher left to trigger another attempt.
284+ logger . error ( `Could not restart the dev server: ${ detail } ` )
285+ process . exit ( 1 )
286286 }
287+ logger . error ( `Could not restart the dev server, keeping the current one: ${ detail } ` )
288+ onRestart ( restart )
287289 return
288290 }
289291
290292 serving = true
291293 fork . promote ( )
292294 const closePrevious = handover ? closeCurrent : undefined
293- cleanupCurrentFork = fork . close
294295 closeCurrent = fork . close
295296 currentPid = fork . pid ?? currentPid
296297 await closePrevious ?.( )
@@ -303,7 +304,9 @@ const command = defineCommand({
303304 onRestart ( restart )
304305
305306 async function closeAll ( ) {
306- await cleanupCurrentFork ?.( )
307+ if ( closeCurrent !== close ) {
308+ await closeCurrent ( )
309+ }
307310 await close ( )
308311 }
309312
0 commit comments