v2.2.1: add 180s upstream timeout to prevent hanging connections

- All urlopen() calls now have timeout=180 to prevent infinite hangs
- Crof upstream can idle between SSE chunks, causing proxy to block forever
- Tested: kimi-k2.6 + mimo-v2.5-pro both stream completed successfully
This commit is contained in:
Roman
2026-05-20 14:04:11 +04:00
Unverified
parent 881f4f35d2
commit 60106955ab
2 changed files with 3 additions and 3 deletions

Binary file not shown.

View File

@@ -1035,7 +1035,7 @@ class Handler(http.server.BaseHTTPRequestHandler):
if stream:
try:
upstream = urllib.request.urlopen(req)
upstream = urllib.request.urlopen(req, timeout=180)
except urllib.error.HTTPError as e:
err = e.read().decode()
return self.send_json(e.code, {"error": {"type": "upstream_error", "message": err}})
@@ -1064,7 +1064,7 @@ class Handler(http.server.BaseHTTPRequestHandler):
store_response(last_resp_id, body.get("input", ""), last_output)
else:
try:
upstream = urllib.request.urlopen(req)
upstream = urllib.request.urlopen(req, timeout=180)
except urllib.error.HTTPError as e:
err = e.read().decode()
return self.send_json(e.code, {"error": {"type": "upstream_error", "message": err}})
@@ -1081,7 +1081,7 @@ class Handler(http.server.BaseHTTPRequestHandler):
def _forward(self, req, stream, model, nonstream_fn, stream_fn, input_data=None):
try:
upstream = urllib.request.urlopen(req)
upstream = urllib.request.urlopen(req, timeout=180)
except urllib.error.HTTPError as e:
err = e.read().decode()
return self.send_json(e.code, {"error": {"type": "upstream_error", "message": err}})