mirror of
https://github.com/kubernetes/kubernetes.git
synced 2026-05-28 04:04:39 -04:00
controller/ttl: Improve goroutine mgmt
Make sure all threads are terminated when Run returns.
This commit is contained in:
parent
3ee8c53e53
commit
7240649e4f
1 changed files with 11 additions and 4 deletions
|
|
@ -122,19 +122,26 @@ var (
|
|||
// Run begins watching and syncing.
|
||||
func (ttlc *Controller) Run(ctx context.Context, workers int) {
|
||||
defer utilruntime.HandleCrash()
|
||||
defer ttlc.queue.ShutDown()
|
||||
|
||||
logger := klog.FromContext(ctx)
|
||||
logger.Info("Starting TTL controller")
|
||||
defer logger.Info("Shutting down TTL controller")
|
||||
|
||||
var wg sync.WaitGroup
|
||||
defer func() {
|
||||
logger.Info("Shutting down TTL controller")
|
||||
ttlc.queue.ShutDown()
|
||||
wg.Wait()
|
||||
}()
|
||||
|
||||
if !cache.WaitForNamedCacheSyncWithContext(ctx, ttlc.hasSynced) {
|
||||
return
|
||||
}
|
||||
|
||||
for i := 0; i < workers; i++ {
|
||||
go wait.UntilWithContext(ctx, ttlc.worker, time.Second)
|
||||
wg.Go(func() {
|
||||
wait.UntilWithContext(ctx, ttlc.worker, time.Second)
|
||||
})
|
||||
}
|
||||
|
||||
<-ctx.Done()
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue