From 17e315f6e9f7aeb905846f6e13409e2f2da3332f Mon Sep 17 00:00:00 2001 From: Hermes Admin Date: Sun, 24 May 2026 12:17:50 +0800 Subject: [PATCH] feat: early port availability check before custom node loading (#13096) Move port check to the start of main.py (before custom node initialization) so users get immediate feedback if the port is already in use, instead of waiting through slow custom node loading. - Uses socket.connect_ex() on 127.0.0.1:{port} - Prints clear error message and exits with code 1 if port taken - +12 lines, no new dependencies --- main.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/main.py b/main.py index 1e47cab84..ff2de51ff 100644 --- a/main.py +++ b/main.py @@ -37,6 +37,18 @@ if __name__ == "__main__": os.environ['HF_HUB_DISABLE_TELEMETRY'] = '1' os.environ['DO_NOT_TRACK'] = '1' + # Early port availability check — fail fast before slow custom node loading + import socket as _early_socket + _port = getattr(args, 'port', 8188) + try: + with _early_socket.socket(_early_socket.AF_INET, _early_socket.SOCK_STREAM) as s: + s.settimeout(1) + if s.connect_ex(('127.0.0.1', _port)) == 0: + print(f"ERROR: Port {_port} is already in use. Please free the port or specify a different one with --port.", file=sys.stderr) + raise SystemExit(1) + except OSError: + pass + faulthandler.enable(file=sys.stderr, all_threads=False) import comfy_aimdo.control