mirror of
https://github.com/zhayujie/chatgpt-on-wechat.git
synced 2026-07-22 06:37:11 +08:00
fix: increase web console capacity and add frontend retry
This commit is contained in:
@@ -763,6 +763,10 @@ function sendMessage() {
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const MAX_RETRIES = 2;
|
||||||
|
const RETRY_DELAY_MS = 1000;
|
||||||
|
|
||||||
|
function postWithRetry(attempt) {
|
||||||
fetch('/message', {
|
fetch('/message', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: { 'Content-Type': 'application/json' },
|
headers: { 'Content-Type': 'application/json' },
|
||||||
@@ -783,11 +787,24 @@ function sendMessage() {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
|
if (err.name === 'AbortError') {
|
||||||
loadingEl.remove();
|
loadingEl.remove();
|
||||||
addBotMessage(err.name === 'AbortError' ? t('error_timeout') : t('error_send'), new Date());
|
addBotMessage(t('error_timeout'), new Date());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (attempt < MAX_RETRIES) {
|
||||||
|
console.warn(`[sendMessage] attempt ${attempt + 1} failed, retrying...`, err);
|
||||||
|
setTimeout(() => postWithRetry(attempt + 1), RETRY_DELAY_MS * (attempt + 1));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
loadingEl.remove();
|
||||||
|
addBotMessage(t('error_send'), new Date());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
postWithRetry(0);
|
||||||
|
}
|
||||||
|
|
||||||
function startSSE(requestId, loadingEl, timestamp) {
|
function startSSE(requestId, loadingEl, timestamp) {
|
||||||
const es = new EventSource(`/stream?request_id=${encodeURIComponent(requestId)}`);
|
const es = new EventSource(`/stream?request_id=${encodeURIComponent(requestId)}`);
|
||||||
activeStreams[requestId] = es;
|
activeStreams[requestId] = es;
|
||||||
|
|||||||
@@ -454,8 +454,14 @@ class WebChannel(ChatChannel):
|
|||||||
func = web.httpserver.StaticMiddleware(app.wsgifunc())
|
func = web.httpserver.StaticMiddleware(app.wsgifunc())
|
||||||
func = web.httpserver.LogMiddleware(func)
|
func = web.httpserver.LogMiddleware(func)
|
||||||
server = web.httpserver.WSGIServer(("0.0.0.0", port), func)
|
server = web.httpserver.WSGIServer(("0.0.0.0", port), func)
|
||||||
# Allow concurrent requests by not blocking on in-flight handler threads
|
|
||||||
server.daemon_threads = True
|
server.daemon_threads = True
|
||||||
|
# Default request_queue_size(5) / timeout(10s) / numthreads(10) are
|
||||||
|
# too small: when SSE streams occupy many threads, the backlog fills
|
||||||
|
# and new connections get refused (ERR_CONNECTION_ABORTED).
|
||||||
|
server.request_queue_size = 128
|
||||||
|
server.timeout = 300
|
||||||
|
server.requests.min = 20
|
||||||
|
server.requests.max = 80
|
||||||
self._http_server = server
|
self._http_server = server
|
||||||
try:
|
try:
|
||||||
server.start()
|
server.start()
|
||||||
|
|||||||
Reference in New Issue
Block a user