fix: in case of port busy because of Services on Windows, a "lacking permission" was displayed instead of "port busy"
Massimo Melina committed
Mar 9, 2025 at 23:06 UTC
fc2426ced1a386a95a40a6492d1ba923b9a09c0a
1 file changed
+6
-5
src/listen.ts
+6
-5
@@ -238,13 +238,14 @@ export function startServer(srv: typeof httpSrv, { port, host }: StartServer) {
238
srv.error = String(e)
239
srv.busy = undefined
240
const { code } = e as any
241
- if (code === 'EACCES' && port < 1024)
241
+ if (code)
242
+ srv.busy = findProcess('port', port).then(
243
+ res => res?.map(x => prefix("Service", x.name === 'svchost.exe' && x.cmd.split(x.name)[1]?.trim()) || x.name).join(' + '),
244
+ () => '')
245
+ if (code === 'EACCES' && port < 1024 && !srv.busy) // on Windows, when port is used by a service, we get EACCESS
246
srv.error = `lacking permission on port ${port}, try with permission (${IS_WINDOWS ? 'administrator' : 'sudo'}) or port > 1024`
243
- if (code === 'EADDRINUSE') {
244
- srv.busy = findProcess('port', port).then(res =>
245
- res?.map(x => prefix("Service", x.name === 'svchost.exe' && x.cmd.split(x.name)[1]?.trim()) || x.name).join(' + '), () => '')
247
+ if (code === 'EADDRINUSE' || srv.busy)
248
srv.error = `port ${port} busy: ${await srv.busy || "unknown process"}`
247
- }
249
if (!silence)
250
console.error(srv.name, srv.error)
251
resolve(0)