Skip to content

Commit 4c7c4a1

Browse files
committed
fix cancel
Signed-off-by: liubo02 <liubo02@pingcap.com>
1 parent 153f674 commit 4c7c4a1

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

pkg/timanager/util.go

+10-1
Original file line numberDiff line numberDiff line change
@@ -132,13 +132,16 @@ type cached[Client, UnderlayClient any] struct {
132132
f SharedInformerFactory[UnderlayClient]
133133

134134
cacheKeys []string
135+
136+
stopCh chan struct{}
135137
}
136138

137139
func NewCache[Client, UnderlayClient any](keys []string, c Client, f SharedInformerFactory[UnderlayClient]) Cache[Client, UnderlayClient] {
138140
return &cached[Client, UnderlayClient]{
139141
c: c,
140142
f: f,
141143
cacheKeys: keys,
144+
stopCh: make(chan struct{}),
142145
}
143146
}
144147

@@ -155,9 +158,15 @@ func (c *cached[Client, UnderlayClient]) Keys() []string {
155158
}
156159

157160
func (c *cached[Client, UnderlayClient]) Start(ctx context.Context) {
158-
c.f.Start(ctx.Done())
161+
go func() {
162+
<-ctx.Done()
163+
c.Stop()
164+
}()
165+
166+
c.f.Start(c.stopCh)
159167
}
160168

161169
func (c *cached[Client, UnderlayClient]) Stop() {
170+
close(c.stopCh)
162171
c.f.Shutdown()
163172
}

0 commit comments

Comments
 (0)