登记账号删除运行时收束任务

This commit is contained in:
Christ committed 2026-08-15 14:56:27 +08:00
1 parent 12a79d4f62
commit 70378afd23
3 files changed
+12 -2

No files matched your search

@@ -732,3 +732,4 @@ npm --prefix frontend run build
| 2026-08-15 | P0 敏感设置跨方言回归补强 | 已完成 | `TestMultiDB_SettingsQuoteKey` 新增敏感设置 `replace/retain/clear`、脱敏读取和密文解密回归;SQLite 在当前环境执行通过,MySQL/Postgres 仅在 `TEST_MYSQL_URL`/`TEST_POSTGRES_URL` 提供时自动加入,当前环境未提供外部数据库,因此不宣称三库实测完成。P0 的运维输出和敏感访问审计仍待完成 |
| 2026-08-15 | P1 应用 Port 类型架构门禁切片 | 已完成 | `architecturecheck` 改用完整 AST 扫描 `internal/application` 类型声明,主动拒绝 `db.*`、`sql.Tx` 和 `*Server` 泄露;新增正反例门禁测试;现有订单 Port 通过扫描,架构门禁与中文注释门禁通过。Server 允许边、订单平台 Port 和其他应用服务仍需继续迁移,不能据此宣称目标架构完成 |
| 2026-08-15 | P1 生命周期上下文边界切片 | 已完成 | `Account.StopContext`、`Manager.StopContext/StopAllContext` 和 `Server.Stop` 的 HTTP、后台任务及 worker 等待均受调用方 Context 限制;超时后未完成账号仍保留在管理表,避免误报已清理;`cmd/server` 使用关闭上下文停止账号;新增账号与 Server 超时回归及聚焦 race 测试通过。账号删除游离 goroutine、调度器等待和删除 fencing 仍未完成,阶段 5 继续保持“进行中” |
| 2026-08-15 | P1 账号删除停止任务登记切片 | 已完成 | 删除账号后的 `Manager.StopContext` 不再通过游离 goroutine 调用,而是登记到 Server `backgroundWG`;Server 关闭会等待或按 Context 收束该任务;新增删除 handler 等待后台任务回归。删除状态 fencing、任务 ID 和调度器 Context-aware 等待仍未完成,阶段 5 继续保持“进行中” |
+9 -2
View File
@@ -708,9 +708,16 @@ func (s *Server) deleteCookie(w http.ResponseWriter, r *http.Request) {
"user_id", ownedDetail.UserID,
)
// Stop 可能需要等待运行中任务收尾,不应阻塞删除 HTTP 请求。
// 数据库事务已完成,先向前端确认删除,再在后台精确停止该 cid 的实例。
// 数据库事务已完成,先向前端确认删除,再将精确停止该 cid 的任务登记到 Server 生命周期。
if s.Manager != nil {
go s.Manager.Stop(cid)
// lifecycleCtx 是删除后运行时收束使用的 Server 生命周期上下文。
lifecycleCtx := s.lifecycleContext()
s.startBackgroundTask("删除账号运行时收束", func() {
// err 表示删除账号运行时停止失败或生命周期上下文已到期。
if err := s.Manager.StopContext(lifecycleCtx, cid); err != nil && s.Logger != nil {
s.Logger.Warn("删除账号后停止运行时失败", "cookie_id", cid, "err", err)
}
})
}
writeJSON(w, http.StatusOK, operationResponse{Success: true})
}
+2
View File
@@ -989,6 +989,8 @@ func TestDeleteCookie(t *testing.T) {
if rec.Code != 200 {
t.Fatalf("delete status=%d", rec.Code)
}
// 删除后的运行时停止必须登记到 Server 生命周期,等待其完成后再验证清理结果。
srv.WaitForBackground()
if // err 保存err,供当前处理流程使用
_, err := store.Cookies.GetDetails(ctx, "acc-del"); !errors.Is(err, db.ErrNotFound) {
t.Fatalf("目标账号应被删除,err=%v", err)