From 9bc13b0bc83955d6691ed1b1dfade327bc95d57f Mon Sep 17 00:00:00 2001 From: umsangdon Date: Sun, 16 Aug 2026 23:05:56 +0900 Subject: [PATCH] =?UTF-8?q?fix(main):=20=ED=8F=AC=ED=8A=B8=20=EC=A0=95?= =?UTF-8?q?=EB=A6=AC=20netstat=20=EC=9D=B8=EC=BD=94=EB=94=A9=20=E2=80=94?= =?UTF-8?q?=20=ED=95=9C=EA=B8=80=20Windows=EC=97=90=EC=84=9C=20UnicodeDeco?= =?UTF-8?q?deError=EB=A1=9C=20=EC=A3=BD=EB=8D=98=20=EB=AC=B8=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `_free_dev_port`의 netstat 호출이 text=True만 주고 encoding을 지정하지 않아 기본 utf-8로 읽었다. 한글 Windows의 netstat는 콘솔 코드페이지(cp949)로 찍으므로 한글 헤더의 0xbc 바이트에서 디코딩이 터졌고, 그 예외가 subprocess 읽기 스레드에서 발생해 try/except로도 잡히지 않았다. 시스템 기본 인코딩으로 읽고 깨진 바이트는 대체 문자로 넘긴다 — 이 함수가 보는 값은 포트 번호와 PID뿐이라 한글 헤더는 읽지 못해도 무방하다. Co-Authored-By: Claude Fable 5 --- main.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) 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