kill-port
kill-port copied to clipboard
It takes too long to kill with version 2.0
I rolled back to version 1 because it takes too much time to kill a process compared to version 1 It also throws an error if port is not found.
I think it's better to keep the existing logic to kill a port
lsof -i ${method === 'udp' ? 'udp' : 'tcp'}:${port} instead of using lsof -i -P, which takes too much time
IMO kill() must resolve when
- when a port is found and kill
- when a port is not found and nothing to kill
Yeah, I also noticed it is quite slow.
This happened after adding a feature to throw if a process is not running on the provided port. Which prompted the major version bump. I think it would be best to revert to the previous v1 behavior and add the throw if the process is not running on the port as an additional configuration option.
For now, i rollback to prev version: npm install --save [email protected]
I can confirm that running kill-port on Macbook Air M1 took about 8 seconds.
I hope you can find a solution soon. Thank you very much for this package @tiaanduplessis
I can also confirm the performance hit using a macos. Downgrading to 1.6.1 🤝
The issue isn't specific to mac. Experience it on ubuntu 22.04. IIRC, the issue wasn't exist on my old laptop with ubuntu 20.04.
I think it would be best to revert to the previous v1 behavior and add the throw if the process is not running on the port as an additional configuration option.
Do you still have plans to do this @tiaanduplessis ? 🤝
Adding this entry to the scripts section of your package.json replaces this package, if you don't need to support windows (and only care about tcp though you could make a separate entry for udp ports):
"kill-port": "lsof -i tcp:${0} | grep LISTEN | awk '{print $2}' | xargs -r kill -9"
Can then do yarn kill-port <port> or npm run kill-port -- <port>. The -r part of xargs should ensure its compatibility with linux, in the "nothing to kill" case.
The issue is related to reverse lookup of IP addresses to hostnames, which is done when calling lsof -i -P. If you have many processes running and several network interfaces active this can take fairly long. On my MacBook it takes currently about 20 seconds.
The solution is simple. Add the option -n to disable reverse lookup (lsof -i -P -n). As the code in index.js is not interested in the hostnames and will not break in my opinion.