From 94b2bb1d3dcfe7973329cc56024f449adde4086c Mon Sep 17 00:00:00 2001 From: "Dr. Stefan Schimanski" Date: Fri, 8 Oct 2021 17:05:27 +0200 Subject: [PATCH] apiserver/watchcache: doc watch event fan-out to blocked watchers better --- staging/src/k8s.io/apiserver/pkg/storage/cacher/cacher.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/staging/src/k8s.io/apiserver/pkg/storage/cacher/cacher.go b/staging/src/k8s.io/apiserver/pkg/storage/cacher/cacher.go index a47d92bc5dd..9540a529fc4 100644 --- a/staging/src/k8s.io/apiserver/pkg/storage/cacher/cacher.go +++ b/staging/src/k8s.io/apiserver/pkg/storage/cacher/cacher.go @@ -934,8 +934,11 @@ func (c *Cacher) dispatchEvent(event *watchCacheEvent) { timeout := c.dispatchTimeoutBudget.takeAvailable() c.timer.Reset(timeout) - // Make sure every watcher will try to send event without blocking first, - // even if the timer has already expired. + // Send event to all blocked watchers. As long as timer is running, + // `add` will wait for the watcher to unblock. After timeout, + // `add` will not wait, but immediately close a still blocked watcher. + // Hence, every watcher gets the chance to unblock itself while timer + // is running, not only the first ones in the list. timer := c.timer for _, watcher := range c.blockedWatchers { if !watcher.add(event, timer) {