From 5a96092dd97bd12dc1b8010748bc146b21f61d55 Mon Sep 17 00:00:00 2001 From: Alvaro Aleman Date: Thu, 4 Apr 2024 15:36:07 -0700 Subject: [PATCH] :bug: Prevent race when informers are started more than once If `Informers` are started a second time, there is a possibility for a data race because it sets a `ctx` field on itself. This write is protected by a mutex, but reads from that field are not. --- pkg/cache/internal/informers.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pkg/cache/internal/informers.go b/pkg/cache/internal/informers.go index c270e809ca..62b7244210 100644 --- a/pkg/cache/internal/informers.go +++ b/pkg/cache/internal/informers.go @@ -18,6 +18,7 @@ package internal import ( "context" + "errors" "fmt" "math/rand" "net/http" @@ -186,6 +187,12 @@ type Informers struct { // Start calls Run on each of the informers and sets started to true. Blocks on the context. // It doesn't return start because it can't return an error, and it's not a runnable directly. func (ip *Informers) Start(ctx context.Context) error { + select { + case <-ip.startWait: + return errors.New("Informrmer already started") + default: + // do nothing + } func() { ip.mu.Lock() defer ip.mu.Unlock()