fix(main): 포트 정리 netstat 인코딩 — 한글 Windows에서 UnicodeDecodeError로 죽던 문제

`_free_dev_port`의 netstat 호출이 text=True만 주고 encoding을 지정하지 않아
기본 utf-8로 읽었다. 한글 Windows의 netstat는 콘솔 코드페이지(cp949)로 찍으므로
한글 헤더의 0xbc 바이트에서 디코딩이 터졌고, 그 예외가 subprocess 읽기 스레드에서
발생해 try/except로도 잡히지 않았다.

시스템 기본 인코딩으로 읽고 깨진 바이트는 대체 문자로 넘긴다 — 이 함수가 보는 값은
포트 번호와 PID뿐이라 한글 헤더는 읽지 못해도 무방하다.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
2026-08-16 23:05:56 +09:00
co-authored by Claude Fable 5
parent 4af0dbdb8a
commit 9bc13b0bc8
+11 -1
View File
@@ -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