Skip to content

Commit 79cff61

Browse files
committed
Don't kill all PIDs connected to a port, only kill the LISTENING PIDs. This was accidentally killing the server, disconnecting everybody.
1 parent 12c27cc commit 79cff61

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

server/utils/appium_driver.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ def _check_appium_health(self, email: str) -> bool:
236236
try:
237237
# Check if anything is listening on the port first
238238
port_check = subprocess.run(
239-
["lsof", "-i", f":{port}", "-t"], capture_output=True, text=True, check=False
239+
["lsof", "-i", f":{port}", "-sTCP:LISTEN", "-t"], capture_output=True, text=True, check=False
240240
)
241241
if not port_check.stdout.strip():
242242
return False
@@ -417,7 +417,7 @@ def _kill_process_on_port(self, port: int):
417417
"""Kill any process using the specified port."""
418418
try:
419419
port_check = subprocess.run(
420-
["lsof", "-i", f":{port}", "-t"], capture_output=True, text=True, check=False
420+
["lsof", "-i", f":{port}", "-sTCP:LISTEN", "-t"], capture_output=True, text=True, check=False
421421
)
422422
if port_check.stdout.strip():
423423
pids = port_check.stdout.strip().split("\n")

server/utils/emulator_shutdown_manager.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,9 @@ def _kill_process_on_port(self, port: int) -> None: # noqa: ANN001, D401
454454
if not port:
455455
return
456456
try:
457-
result = subprocess.run(["lsof", "-i", f":{port}", "-t"], capture_output=True, text=True)
457+
result = subprocess.run(
458+
["lsof", "-i", f":{port}", "-sTCP:LISTEN", "-t"], capture_output=True, text=True
459+
)
458460
for pid in filter(None, result.stdout.split()):
459461
with contextlib.suppress(Exception):
460462
os.kill(int(pid), signal.SIGTERM)

0 commit comments

Comments
 (0)