Skip to content

Commit

Permalink
🐛 Prevent race when informers are started more than once
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
alvaroaleman committed Apr 4, 2024
1 parent a17fd58 commit 5a96092
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions pkg/cache/internal/informers.go
Expand Up @@ -18,6 +18,7 @@ package internal

import (
"context"
"errors"
"fmt"
"math/rand"
"net/http"
Expand Down Expand Up @@ -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")

Check failure on line 192 in pkg/cache/internal/informers.go

View workflow job for this annotation

GitHub Actions / lint

ST1005: error strings should not be capitalized (stylecheck)

Check failure on line 192 in pkg/cache/internal/informers.go

View workflow job for this annotation

GitHub Actions / lint

ST1005: error strings should not be capitalized (stylecheck)
default:
// do nothing
}
func() {
ip.mu.Lock()
defer ip.mu.Unlock()
Expand Down

0 comments on commit 5a96092

Please sign in to comment.