수정
This commit is contained in:
@@ -474,31 +474,32 @@ class KisRealtimeStream:
|
||||
# WebSocket handshake returned a non-101 HTTP response (often 200)
|
||||
connection_attempts += 1
|
||||
status = getattr(isc, 'status_code', None)
|
||||
# 진단 로그는 처음 3회만 출력 (로그 도배 방지)
|
||||
if connection_attempts <= 3:
|
||||
logger.error(f"❌ KIS WS InvalidStatusCode: HTTP {status}")
|
||||
# Try HTTP GET diagnostic (replace wss:// -> https://)
|
||||
if _httpx is not None:
|
||||
try:
|
||||
http_url = ws_full_url.replace('wss://', 'https://')
|
||||
logger.info(f"🔍 Performing HTTP GET diagnostic to {http_url}")
|
||||
async with _httpx.AsyncClient(timeout=10.0, verify=True) as client:
|
||||
# include Origin in diagnostic GET if available to mirror websocket handshake
|
||||
diag_headers = {"User-Agent": "Mozilla/5.0"}
|
||||
if origin:
|
||||
diag_headers["Origin"] = origin
|
||||
resp = await client.get(http_url, headers=diag_headers)
|
||||
headers_snippet = dict(list(resp.headers.items())[:10])
|
||||
body_snippet = (resp.text or '')[:1000]
|
||||
logger.error(f"🔍 Diagnostic HTTP {resp.status_code} headers={headers_snippet} body={body_snippet}")
|
||||
body_snippet = (resp.text or '')[:200]
|
||||
logger.error(f"🔍 Diagnostic HTTP {resp.status_code} body={body_snippet}")
|
||||
except Exception as diag_exc:
|
||||
logger.error(f"🔍 Diagnostic HTTP GET failed: {diag_exc}", exc_info=True)
|
||||
else:
|
||||
logger.error("🔍 httpx not installed — cannot perform HTTP diagnostic")
|
||||
# reset ws state and approval_key to attempt re-issue on next loop
|
||||
logger.error(f"🔍 Diagnostic HTTP GET failed: {diag_exc}")
|
||||
elif connection_attempts == 4:
|
||||
logger.warning(
|
||||
f"⚠️ KIS WS 서버 비정상 (HTTP {status} 반환). "
|
||||
f"5분 간격으로 재시도합니다. REST API는 정상 동작합니다."
|
||||
)
|
||||
# reset ws state
|
||||
self._ws = None
|
||||
self._subscribed_codes.clear()
|
||||
self._approval_key = None
|
||||
# continue to retry after outer sleep
|
||||
continue
|
||||
# outer backoff로 이동 (continue 제거)
|
||||
|
||||
except ConnectionClosed as e:
|
||||
connection_attempts += 1
|
||||
|
||||
Reference in New Issue
Block a user