Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

policy: lazily start SelectorCache.handleUserNotifications #24325

Merged
merged 1 commit into from
Mar 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion daemon/cmd/cells_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ var goleakOptions = []goleak.Option{
// Ignore goroutines started by the policy trifecta, see [newPolicyTrifecta].
goleak.IgnoreTopFunction("github.com/cilium/cilium/pkg/identity/cache.(*identityWatcher).watch.func1"),
goleak.IgnoreTopFunction("github.com/cilium/cilium/pkg/trigger.(*Trigger).waiter"),
goleak.IgnoreTopFunction("sync.runtime_notifyListWait"),
}

// TestAgentCell verifies that the Agent hive can be instantiated with
Expand Down
8 changes: 6 additions & 2 deletions pkg/policy/selectorcache.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,9 @@ type SelectorCache struct {
userMutex lock.Mutex
// userNotes holds a FIFO list of user notifications to be made
userNotes []userNotification

// used to lazily start the handler for user notifications.
startNotificationsHandlerOnce sync.Once
}

// GetModel returns the API model of the SelectorCache.
Expand Down Expand Up @@ -267,6 +270,9 @@ func (sc *SelectorCache) handleUserNotifications() {
}

func (sc *SelectorCache) queueUserNotification(user CachedSelectionUser, selector CachedSelector, added, deleted []identity.NumericIdentity, wg *sync.WaitGroup) {
sc.startNotificationsHandlerOnce.Do(func() {
go sc.handleUserNotifications()
})
wg.Add(1)
sc.userMutex.Lock()
sc.userNotes = append(sc.userNotes, userNotification{
Expand All @@ -288,8 +294,6 @@ func NewSelectorCache(allocator cache.IdentityAllocator, ids cache.IdentityCache
selectors: make(map[string]identitySelector),
}
sc.userCond = sync.NewCond(&sc.userMutex)
go sc.handleUserNotifications()

return sc
}

Expand Down