Skip to content

Commit

Permalink
Fix additional panic
Browse files Browse the repository at this point in the history
Ensure we take the incomingBlock Lock
in blockQueue to ensure there
is not any possiblity of sending on a
closed incoming channel.

Signed-off-by: Andrew Stoycos <astoycos@redhat.com>
  • Loading branch information
astoycos committed May 16, 2022
1 parent 2d614a1 commit b7a37f5
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions staging/src/k8s.io/apimachinery/pkg/watch/mux.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ type Broadcaster struct {
distributing sync.WaitGroup

// incomingBlock allows us to ensure we don't race and end up sending events
// to a closed channel following a brodcaster shutdown.
// to a closed channel following a broadcaster shutdown.
incomingBlock sync.Mutex
incoming chan Event
stopped chan struct{}
Expand Down Expand Up @@ -115,6 +115,8 @@ func (obj functionFakeRuntimeObject) DeepCopyObject() runtime.Object {
// won't ever see that event, and will always see any event after they are
// added.
func (m *Broadcaster) blockQueue(f func()) {
m.incomingBlock.Lock()
defer m.incomingBlock.Unlock()
select {
case <-m.stopped:
return
Expand Down Expand Up @@ -252,8 +254,6 @@ func (m *Broadcaster) ActionOrDrop(action EventType, obj runtime.Object) (bool,
// have received the data yet as it can remain sitting in the buffered
// channel. It will block until the broadcaster stop request is actually executed
func (m *Broadcaster) Shutdown() {
m.incomingBlock.Lock()
defer m.incomingBlock.Unlock()
m.blockQueue(func() {
close(m.stopped)
close(m.incoming)
Expand Down

0 comments on commit b7a37f5

Please sign in to comment.