diff --git a/main.py b/main.py index 74e3c91b..b70bbd92 100644 --- a/main.py +++ b/main.py @@ -10,6 +10,7 @@ FastAPI 애플리케이션 진입점 """ import asyncio +import locale import logging import os import signal @@ -150,8 +151,17 @@ def _free_dev_port(port: int) -> None: if os.name != "nt": return try: + # 한글 Windows의 netstat는 콘솔 코드페이지(cp949)로 찍는다 — 기본 utf-8로 읽으면 + # 한글 헤더에서 UnicodeDecodeError가 나고, 그 예외가 읽기 스레드에서 터져 + # 포트 정리가 통째로 죽는다(2026-08-16 실제 발생). 시스템 인코딩으로 읽고, + # 깨지는 바이트는 넘긴다 — 우리가 볼 것은 숫자 포트·PID뿐이다. result = subprocess.run( - ["netstat", "-ano", "-p", "TCP"], check=False, capture_output=True, text=True + ["netstat", "-ano", "-p", "TCP"], + check=False, + capture_output=True, + text=True, + encoding=locale.getpreferredencoding(False), + errors="replace", ) except Exception: return