unlock mutex after handling event, now with non-blocking default case

This commit is contained in:
Felix Kunde 2022-05-16 12:36:27 +02:00
parent 125512eb82
commit 264e66d0a1
1 changed files with 7 additions and 2 deletions

View File

@ -1034,10 +1034,15 @@ func (c *Cluster) processPodEvent(obj interface{}) error {
c.podSubscribersMu.RLock() c.podSubscribersMu.RLock()
subscriber, ok := c.podSubscribers[spec.NamespacedName(event.PodName)] subscriber, ok := c.podSubscribers[spec.NamespacedName(event.PodName)]
c.podSubscribersMu.RUnlock()
if ok { if ok {
subscriber <- event select {
case subscriber <- event:
default:
// we end up here when there is no receiver of the channel
// avoiding a deadlock: https://gobyexample.com/non-blocking-channel-operations
}
} }
c.podSubscribersMu.RUnlock()
return nil return nil
} }