fix: remove incorrect port-in-use check for reverse tunnels
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 <noreply@anthropic.com>
This commit is contained in:
@@ -2,7 +2,6 @@ import os
|
|||||||
import shlex
|
import shlex
|
||||||
import shutil
|
import shutil
|
||||||
import signal
|
import signal
|
||||||
import socket
|
|
||||||
import subprocess
|
import subprocess
|
||||||
import time
|
import time
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
@@ -115,20 +114,9 @@ def build_autossh_cmd(tunnel: TunnelConfig) -> list[str]:
|
|||||||
return cmd
|
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:
|
def start_tunnel(config_dir: Path, tunnel: TunnelConfig) -> int:
|
||||||
if not shutil.which("autossh"):
|
if not shutil.which("autossh"):
|
||||||
raise click.ClickException("autossh not found. Install it first.")
|
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 = config_dir / "logs" / f"{tunnel.name}.log"
|
||||||
log_path.parent.mkdir(parents=True, exist_ok=True)
|
log_path.parent.mkdir(parents=True, exist_ok=True)
|
||||||
|
|||||||
Reference in New Issue
Block a user