fix(models): 同步模型改为异步触发,避免 Cloudflare 100s 超时 - #899
Merged
Conversation
# Conflicts: # frontend/src/shared/i18n/index.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
为什么同步模型按钮会报 "Failed to fetch"?
根因: 同步模型是全量同步所有启用账号的上游模型能力,耗时超过 2 分钟。Cloudflare 免费版 origin timeout 上限 100s,Nginx 默认 proxy_read_timeout 60s,请求在中间层被掐断 → 浏览器收到连接中断 →
Failed to fetch。改动: 后端
/api/admin/v1/models/sync改为异步触发:200 {"synced":0,"async":true}Service.SyncAsync,用context.Background()触发同步,请求断开不影响同步继续执行singleflight(DoChan("all", ...))去重,并发点击只会同步一次验证: 修复前直接调 API 126s 后被 Cloudflare 掐断(HTTP 524);修复后立即返回 200,后台同步正常完成。
附加说明: 上游 README 中已建议
proxy_read_timeout 600s,但 Cloudflare 免费版 100s 上限无法通过 Nginx 配置绕过,因此异步触发是更稳妥的解法。