From 4c9cd00c908fe359429b09362c11a5d909396d7a Mon Sep 17 00:00:00 2001 From: tech Date: Thu, 21 May 2026 18:00:11 +0800 Subject: [PATCH] fix: remove incorrect port-in-use check for reverse tunnels MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The `_is_port_in_use` bind check was wrong for `-R` tunnels: local_port is the forward target (e.g. a Docker container), so it should be listening, not free. Drop the check — autossh doesn't require the target to be reachable at startup. Co-Authored-By: Claude Opus 4.7 --- src/autossh_mgr/process.py | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/src/autossh_mgr/process.py b/src/autossh_mgr/process.py index 6b351d1..3f7bd00 100644 --- a/src/autossh_mgr/process.py +++ b/src/autossh_mgr/process.py @@ -2,7 +2,6 @@ import os import shlex import shutil import signal -import socket import subprocess import time from dataclasses import dataclass @@ -115,20 +114,9 @@ def build_autossh_cmd(tunnel: TunnelConfig) -> list[str]: return cmd -def _is_port_in_use(port: int) -> bool: - with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: - try: - s.bind(("127.0.0.1", port)) - return False - except OSError: - return True - - def start_tunnel(config_dir: Path, tunnel: TunnelConfig) -> int: if not shutil.which("autossh"): raise click.ClickException("autossh not found. Install it first.") - if _is_port_in_use(tunnel.local_port): - raise click.ClickException(f"Port {tunnel.local_port} is already in use") log_path = config_dir / "logs" / f"{tunnel.name}.log" log_path.parent.mkdir(parents=True, exist_ok=True)