Skip to content

Commit 5a96092

Browse files
committed
🐛 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.
1 parent a17fd58 commit 5a96092

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

pkg/cache/internal/informers.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package internal
1818

1919
import (
2020
"context"
21+
"errors"
2122
"fmt"
2223
"math/rand"
2324
"net/http"
@@ -186,6 +187,12 @@ type Informers struct {
186187
// Start calls Run on each of the informers and sets started to true. Blocks on the context.
187188
// It doesn't return start because it can't return an error, and it's not a runnable directly.
188189
func (ip *Informers) Start(ctx context.Context) error {
190+
select {
191+
case <-ip.startWait:
192+
return errors.New("Informrmer already started")
193+
default:
194+
// do nothing
195+
}
189196
func() {
190197
ip.mu.Lock()
191198
defer ip.mu.Unlock()

0 commit comments

Comments
 (0)