with busy port, show service information on Windows

Massimo Melina committed Jun 9, 2024 at 11:46 UTC 88533494d656bb1915c747b0ee5693cd8ca00ea8
1 file changed +14 -2
src/listen.ts
+14 -2
@@ -8,7 +8,18 @@ import { watchLoad } from './watchLoad'
8 import { networkInterfaces } from 'os';
9 import { newConnection } from './connections'
10 import open from 'open'
11 -import { debounceAsync, ipForUrl, makeNetMatcher, MINUTE, objSameKeys, onlyTruthy, runAt, wait, waitFor } from './misc'
11 +import {
12 + debounceAsync,
13 + ipForUrl,
14 + makeNetMatcher,
15 + MINUTE,
16 + objSameKeys,
17 + onlyTruthy,
18 + prefix,
19 + runAt,
20 + wait,
21 + waitFor
22 +} from './misc'
23 import { PORT_DISABLED, ADMIN_URI, argv, DEV, IS_WINDOWS } from './const'
24 import findProcess from 'find-process'
25 import { anyAccountCanLoginAdmin } from './adminApis'
@@ -214,7 +225,8 @@ export function startServer(srv: typeof httpSrv, { port, host }: StartServer) {
225 if (code === 'EACCES' && port < 1024)
226 srv.error = `lacking permission on port ${port}, try with permission (${IS_WINDOWS ? 'administrator' : 'sudo'}) or port > 1024`
227 if (code === 'EADDRINUSE') {
217 - srv.busy = findProcess('port', port).then(res => res?.[0]?.name || '', () => '')
228 + srv.busy = findProcess('port', port).then(res =>
229 + res?.map(x => prefix("Service", x.name === 'svchost.exe' && x.cmd.split(x.name)[1]?.trim()) || x.name).join(' + '), () => '')
230 srv.error = `port ${port} busy: ${await srv.busy || "unknown process"}`
231 }
232 console.error(srv.name, srv.error)