fix(integration): watcher ticker 接受 ctx 并接入 lifecycle#250
Open
fix(integration): watcher ticker 接受 ctx 并接入 lifecycle#250
Conversation
(*integration).watch started a goroutine with
`for range time.NewTicker(15s).C { GetIntegrations() }` - no ctx,
no Stop, no done signal. The loop kept calling K8s after intended
shutdown, racing with the rest of the teardown.
- Add cancelWatcher / watcherDone fields, build them in watch().
- watch() loops on `select { case <-ctx.Done(): return; case <-tick }`
with `defer ticker.Stop()` and `defer close(watcherDone)`.
- New Stop(ctx) ends the goroutine and waits for it (or returns
ctx.Err() on shutdown deadline).
- cmd/backend/app/root.go registers a "integration-watcher" hook on
the lifecycle coordinator with a 5s budget.
Co-authored-by: Cursor <cursoragent@cursor.com>
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.
概要
`pkg/integration/integration.go` 的 `(*integration).watch` 启动了一个永不退出的 goroutine:
```go
go func() {
for range time.NewTicker(15 * time.Second).C {
i.GetIntegrations()
}
}()
```
进程进入 graceful-shutdown 后这个循环还在以 15s 一次的频率打 K8s API,与其它子系统的关闭逻辑互相干扰。
改动
验证方式
Made with Cursor