Commit c11cc61
committed
feat(usage): add PingCheckCtx for cancellable ping loops
PingCheck runs an unbounded ticker loop with no stop mechanism — once
started, it emits ping events for the entire process lifetime. This
prevents consumers from running ping under cancellation-aware constructs
like leader election, where a pod that loses leadership needs its ping
goroutines to stop cleanly. Without a stop signal, ex-leaders leak
goroutines across every transition and continue emitting duplicate
events from pods that should be quiet.
Add PingCheckCtx(ctx, engineName, category, pingImmediately) alongside
PingCheck. Same semantics, but the ticker loop selects on ctx.Done() and
returns cleanly on cancellation. defer ticker.Stop() to avoid a leaked
ticker on the cancellation path.
Refactor PingCheck into a one-line wrapper around
PingCheckCtx(context.Background(), ...) and mark it Deprecated in the
godoc. Backward-compatible: the signature is unchanged, and under
context.Background() ctx.Done() returns a nil channel that blocks
forever, so the select degrades to the same forever-tick loop as
before.
Signed-off-by: Niladri Halder <niladri.halder26@gmail.com>1 parent c2fca3a commit c11cc61
1 file changed
Lines changed: 23 additions & 25 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
2 | | - | |
3 | | - | |
4 | | - | |
5 | | - | |
6 | | - | |
7 | | - | |
8 | | - | |
9 | | - | |
10 | | - | |
11 | | - | |
12 | | - | |
13 | | - | |
14 | | - | |
15 | | - | |
16 | | - | |
17 | 1 | | |
18 | 2 | | |
19 | 3 | | |
| 4 | + | |
20 | 5 | | |
21 | 6 | | |
22 | 7 | | |
| |||
35 | 20 | | |
36 | 21 | | |
37 | 22 | | |
38 | | - | |
| 23 | + | |
39 | 24 | | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
40 | 32 | | |
41 | 33 | | |
42 | 34 | | |
| |||
48 | 40 | | |
49 | 41 | | |
50 | 42 | | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
59 | 57 | | |
60 | 58 | | |
61 | 59 | | |
| |||
0 commit comments