fix(dev): handle a rejected `reusePort` option and a failed cold restart · nuxt/cli@ae9be91 · GitHub
Skip to content

Commit ae9be91

Browse files
committed
fix(dev): handle a rejected reusePort option and a failed cold restart
1 parent 169f917 commit ae9be91

3 files changed

Lines changed: 37 additions & 16 deletions

File tree

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

Lines changed: 13 additions & 10 deletions

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

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -310,10 +310,18 @@ function bindServer(server: HttpServer, port: number, hostname: string, reusePor
310310
reject(error)
311311
}
312312
server.once('error', onError)
313-
server.listen({ port, host: hostname || undefined, reusePort, exclusive: !reusePort }, () => {
313+
try {
314+
server.listen({ port, host: hostname || undefined, reusePort, exclusive: !reusePort }, () => {
315+
server.removeListener('error', onError)
316+
resolve()
317+
})
318+
}
319+
catch (error) {
320+
// Runtimes that do not know the option reject it before the bind, throwing
321+
// rather than emitting `error`.
314322
server.removeListener('error', onError)
315-
resolve()
316-
})
323+
onError(error as NodeJS.ErrnoException)
324+
}
317325
})
318326
}
319327

@@ -331,7 +339,9 @@ let reusePortSupport: Promise<boolean> | undefined
331339
/**
332340
* Whether two sockets can bind the same port at once via `SO_REUSEPORT`, probed
333341
* on an ephemeral port. A single successful bind is not enough: some platforms
334-
* accept the option and still reject the second socket. Cached per process.
342+
* accept the option and still reject the second socket. Support is a property of
343+
* the platform rather than of an address, so the loopback probe stands in for
344+
* whichever hostname the dev server ends up binding. Cached per process.
335345
*/
336346
export function isReusePortSupported(): Promise<boolean> {
337347
reusePortSupport ??= (async () => {

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

Lines changed: 10 additions & 2 deletions

0 commit comments

Comments
 (0)