-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Add port killer utility for troubleshooting port conflicts #628
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2 issues found across 2 files
Prompt for AI agents (all issues)
Check if these issues are valid — if so, understand the root cause of each and fix them.
<file name="port_killer.py">
<violation number="1" location="port_killer.py:98">
P1: Naive /proc fd substring match can misidentify PIDs and kill unrelated processes; socket fd links don’t contain ports or “TCP”, so this detection is unreliable and can flag non-port users.</violation>
<violation number="2" location="port_killer.py:245">
P1: PermissionError from os.kill(pid, 0) is unhandled, so checking a process owned by another user will crash the script and stop processing remaining ports.</violation>
</file>
Since this is your first cubic review, here's how it works:
- cubic automatically reviews your code and comments on bugs and improvements
- Teach cubic by replying to its comments. cubic learns from your replies and gets better over time
- Ask questions if you need clarification on any suggestion
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
|
|
||
| # Check if dead | ||
| try: | ||
| os.kill(pid, 0) # Signal 0 = check if alive |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P1: PermissionError from os.kill(pid, 0) is unhandled, so checking a process owned by another user will crash the script and stop processing remaining ports.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At port_killer.py, line 245:
<comment>PermissionError from os.kill(pid, 0) is unhandled, so checking a process owned by another user will crash the script and stop processing remaining ports.</comment>
<file context>
@@ -0,0 +1,305 @@
+
+ # Check if dead
+ try:
+ os.kill(pid, 0) # Signal 0 = check if alive
+ print(f" Still alive after kill attempt!")
+
</file context>
| for fd in os.listdir(fd_path): | ||
| try: | ||
| link = os.readlink(f'{fd_path}/{fd}') | ||
| if f':{port}' in link or f'TCP' in link: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P1: Naive /proc fd substring match can misidentify PIDs and kill unrelated processes; socket fd links don’t contain ports or “TCP”, so this detection is unreliable and can flag non-port users.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At port_killer.py, line 98:
<comment>Naive /proc fd substring match can misidentify PIDs and kill unrelated processes; socket fd links don’t contain ports or “TCP”, so this detection is unreliable and can flag non-port users.</comment>
<file context>
@@ -0,0 +1,305 @@
+ for fd in os.listdir(fd_path):
+ try:
+ link = os.readlink(f'{fd_path}/{fd}')
+ if f':{port}' in link or f'TCP' in link:
+ all_pids.add(pid)
+ print(f" Found: {pid} (via /proc)")
</file context>
Pull Request Title
Add port killer utility for troubleshooting port conflicts
Related Issue
N/A - This is a proactive enhancement to help users troubleshoot common port conflict issues
Description
This PR adds a diagnostic utility script that helps users identify and terminate processes occupying ports, particularly useful when Streamlit fails to start due to "Address already in use" errors.
The script uses multiple detection methods (lsof, fuser, netstat, ss, and /proc filesystem) to ensure reliable process identification across different Linux/WSL environments.
Type
Proposed Changes
port_killer.py- comprehensive port diagnostic and process termination utilityScreenshots / Code Snippets (if applicable)
Example usage:
Example output:
How to Test
Checklist
Additional Information
This utility is particularly helpful for:
The script requires no additional dependencies beyond Python standard library and works on Linux/WSL environments. It gracefully handles missing system utilities and provides clear feedback about what was found and terminated.
Summary by cubic
Adds a Linux/WSL port killer utility to quickly diagnose and free busy ports. Helps resolve “Address already in use” errors by finding and terminating offending processes with clear output.
Written for commit c8fd455. Summary will update on new commits.