Skip to content

fix(global/pvc): pvc 刷新 ticker 接受 ctx 并接入 lifecycle#252

Open
pengpeng wants to merge 1 commit intomainfrom
cursor/fix-global-pvc-ticker
Open

fix(global/pvc): pvc 刷新 ticker 接受 ctx 并接入 lifecycle#252
pengpeng wants to merge 1 commit intomainfrom
cursor/fix-global-pvc-ticker

Conversation

@pengpeng
Copy link
Copy Markdown
Member

@pengpeng pengpeng commented May 5, 2026

概要

`pkg/global/pvc.go` 的 `InitGlobalData` 同 B8b 模式:

```go
go func() {
ticker := time.NewTicker(120 * time.Second)
defer ticker.Stop()
for range ticker.C {
GlobalData.getGlobalData()
}
}()
```

`for range ticker.C` 永远不退出,graceful-shutdown 后仍每 120s 打 K8s。

改动

  • `Data` 结构加 `cancel context.CancelFunc` + `done chan struct{}`。
  • goroutine 改为 `select { case <-ctx.Done(): return; case <-tick }`。
  • 提供 `(*Data).Stop(ctx)`:取消 + 等 done。
  • `cmd/backend/app/root.go` 注册 `coord.Add("global-data", 3*time.Second, ...)`。

验证方式

  • `go build` 通过。
  • 手工:触发 SIGTERM,确认 "global-data" 钩子在 redis/postgres 之前完成。

Made with Cursor

InitGlobalData spawned a goroutine that ranged forever over a
120s ticker calling getGlobalData(). No ctx, no done signal -
the loop kept polling K8s past graceful shutdown.

Same shape as the global/node fix: add Data.cancel / Data.done,
switch the loop to select { ctx.Done | tick }, expose Data.Stop(ctx),
and register a "global-data" lifecycle hook in cmd/backend/app/root.go.

Co-authored-by: Cursor <cursoragent@cursor.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant