Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

It takes too long to kill with version 2.0 #61

Open
allenhwkim opened this issue May 16, 2022 · 8 comments
Open

It takes too long to kill with version 2.0 #61

allenhwkim opened this issue May 16, 2022 · 8 comments
Assignees
Labels

Comments

@allenhwkim
Copy link

allenhwkim commented May 16, 2022

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
@tiaanduplessis
Copy link
Owner

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.

@nvh95
Copy link
Contributor

nvh95 commented Jun 20, 2022

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

@filipedeschamps
Copy link

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

@Bessonov
Copy link

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.

@filipedeschamps
Copy link

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

@benasher44
Copy link

benasher44 commented Dec 14, 2022

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.

@rfoerthe
Copy link

rfoerthe commented Nov 8, 2023

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.

Bessonov pushed a commit to Bessonov/monorepo-starter that referenced this issue Nov 17, 2023
- downgrade kill-port because of tiaanduplessis/kill-port#61
Bessonov added a commit to Bessonov/monorepo-starter that referenced this issue Jan 6, 2024
- downgrade kill-port because of tiaanduplessis/kill-port#61
Bessonov added a commit to Bessonov/monorepo-starter that referenced this issue Jan 6, 2024
- downgrade kill-port because of tiaanduplessis/kill-port#61
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

8 participants
@Bessonov @rfoerthe @benasher44 @allenhwkim @filipedeschamps @nvh95 @tiaanduplessis and others