fix: ocg_router single-threaded HTTPServer blocks all requests on large body — switch to ThreadingHTTPServer

This commit is contained in:
hmo
2026-08-10 12:56:01 +08:00
parent 15a97696f7
commit 4b838b5a6b
+3 -3
View File
@@ -21,7 +21,7 @@ OpenAI 兼容代理,背后池化 6 个 OpenCode Go API key。
"""
import os, sys, json, time, logging, threading
from http.server import HTTPServer, BaseHTTPRequestHandler
from http.server import ThreadingHTTPServer, BaseHTTPRequestHandler
from urllib.request import Request, urlopen, HTTPError
from urllib.error import URLError
from datetime import datetime, timezone
@@ -651,8 +651,8 @@ def main():
refresh_thread = threading.Thread(target=_bg_refresh, name="ocg_router_refresh", daemon=True)
refresh_thread.start()
# 启动 HTTP 服务
server = HTTPServer((LISTEN_HOST, LISTEN_PORT), RouterHandler)
# 启动 HTTP 服务ThreadingHTTPServer — 多线程,避免大请求阻塞 /api/status 等监控端点)
server = ThreadingHTTPServer((LISTEN_HOST, LISTEN_PORT), RouterHandler)
log.info("ocg_router 启动 → http://%s:%d", LISTEN_HOST, LISTEN_PORT)
log.info("keys loaded: %d (%d healthy)", len(_keys),
sum(1 for k in _keys if _key_health_score(k["key_id"]) < 888))