From 554eeaf1086388f4b4fef97a0664699ebdfe7bfc Mon Sep 17 00:00:00 2001 From: Vladyslav Klokun Date: Wed, 12 Jun 2024 15:58:09 +0300 Subject: [PATCH] refactor: lock sendMu only once in waitFn --- internal/services/controller/controller.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/internal/services/controller/controller.go b/internal/services/controller/controller.go index 0e180424..5172ed3f 100644 --- a/internal/services/controller/controller.go +++ b/internal/services/controller/controller.go @@ -291,7 +291,7 @@ func (c *Controller) Run(ctx context.Context) error { } // Since Mutex.TryLock() acquires a lock on success, // release it immediately to allow the new sending goroutine to do its job. - c.sendMu.Unlock() + defer c.sendMu.Unlock() c.send(ctx) }, c.cfg.Interval, ctx.Done()) return nil @@ -438,8 +438,6 @@ func (c *Controller) processItem(i interface{}) { func (c *Controller) send(ctx context.Context) { c.deltaMu.Lock() defer c.deltaMu.Unlock() - c.sendMu.Lock() - defer c.sendMu.Unlock() nodesByName := map[string]*corev1.Node{} var nodes []*corev1.Node