kill-port icon indicating copy to clipboard operation
kill-port copied to clipboard

It takes too long to kill with version 2.0

Open allenhwkim opened this issue 3 years ago • 8 comments

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

allenhwkim avatar May 16 '22 15:05 allenhwkim

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.

tiaanduplessis avatar May 17 '22 23:05 tiaanduplessis

For now, i rollback to prev version: npm install --save [email protected]

ahmadkeren avatar May 22 '22 09:05 ahmadkeren

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

Process on port 3337 killed

nvh95 avatar Jun 20 '22 02:06 nvh95

I can also confirm the performance hit using a macos. Downgrading to 1.6.1 🤝

filipedeschamps avatar Jul 28 '22 22:07 filipedeschamps

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.

Bessonov avatar Aug 13 '22 00:08 Bessonov

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 ? 🤝

filipedeschamps avatar Oct 11 '22 20:10 filipedeschamps

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.

benasher44 avatar Dec 14 '22 21:12 benasher44

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.

rfoerthe avatar Nov 08 '23 14:11 rfoerthe