From 03728c1ebef88c3e26a4c5ef7c54f1525985689f Mon Sep 17 00:00:00 2001 From: Keisuke Ishigami Date: Thu, 29 May 2025 00:34:43 +0900 Subject: [PATCH] handle context in process loop Kubernetes-commit: f67d30b3529ea970dd5fd069eaddfc7f61d74169 --- tools/cache/controller.go | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/tools/cache/controller.go b/tools/cache/controller.go index 1497700d..f0a483b6 100644 --- a/tools/cache/controller.go +++ b/tools/cache/controller.go @@ -204,13 +204,15 @@ func (c *controller) LastSyncResourceVersion() string { // concurrently. func (c *controller) processLoop(ctx context.Context) { for { - // TODO: Plumb through the ctx so that this can - // actually exit when the controller is stopped. Or just give up on this stuff - // ever being stoppable. - _, err := c.config.Queue.Pop(PopProcessFunc(c.config.Process)) - if err != nil { - if err == ErrFIFOClosed { - return + select { + case <-ctx.Done(): + return + default: + _, err := c.config.Queue.Pop(PopProcessFunc(c.config.Process)) + if err != nil { + if err == ErrFIFOClosed { + return + } } } }