mirror of
https://github.com/CJackHwang/ds2api.git
synced 2026-05-12 04:07:42 +08:00
fix: 修复会话管理相关问题并拆分文件
1. 修复无限循环问题 - DeleteAllSessions/DeleteAllSessionsForToken 添加无进度检测 - 连续 3 轮删除失败则退出循环 - DeleteAllSessionsForToken 添加 cursor 推进逻辑 2. 修复字段语义不准确 - TotalCount 重命名为 FirstPageCount - 明确该值仅统计第一页,多页账户需关注 HasMore 3. 修复 defer 执行顺序问题 - 合并两个 defer,确保先删除会话再释放账号 - 使用同步删除避免并发截断风险 4. 文件拆分 - 新建 client_session_delete.go 处理会话删除 - client_session.go 专注于会话查询
This commit is contained in:
@@ -35,19 +35,22 @@ func (h *Handler) ChatCompletions(w http.ResponseWriter, r *http.Request) {
|
||||
writeOpenAIError(w, status, detail)
|
||||
return
|
||||
}
|
||||
defer h.Auth.Release(a)
|
||||
|
||||
// 自动删除会话功能
|
||||
if h.Store.AutoDeleteSessions() && a.DeepSeekToken != "" {
|
||||
defer func() {
|
||||
defer func() {
|
||||
// 自动删除会话(同步)
|
||||
// 必须在 Release 之前同步删除,否则:
|
||||
// 1. 异步删除时账号已被 Release
|
||||
// 2. 新请求可能获取到同一账号并开始使用
|
||||
// 3. 异步删除仍在进行,会截断新请求正在使用的会话
|
||||
if h.Store.AutoDeleteSessions() && a.DeepSeekToken != "" {
|
||||
deleted, err := h.DS.DeleteAllSessionsForToken(context.Background(), a.DeepSeekToken)
|
||||
if err != nil {
|
||||
config.Logger.Warn("[auto_delete_sessions] failed", "account", a.AccountID, "error", err)
|
||||
} else {
|
||||
config.Logger.Debug("[auto_delete_sessions] deleted", "account", a.AccountID, "count", deleted)
|
||||
}
|
||||
}()
|
||||
}
|
||||
}
|
||||
h.Auth.Release(a)
|
||||
}()
|
||||
|
||||
r = r.WithContext(auth.WithAuth(r.Context(), a))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user