kubernetes: regression: wait.Forever runs twice immediately since 1.18

I noticed that this code:

	go wait.UntilWithContext(ctx, func(ctx context.Context) {
		now := time.Now()
		refreshAfter := now.Add(-s.refreshInterval)
		var count int
		for _, obj := range s.store.List() {
			comments := obj.(*BugComments)
			if comments.RefreshTime.Before(refreshAfter) {
				s.queue.Add(comments.Name)
				count++
			}
		}
		klog.V(5).Infof("Refreshed %d comments older than %s", count, s.refreshInterval.String())
	}, s.refreshInterval/4)

was printing

I0419 16:20:13.714551  976723 comments.go:122] Refreshed 0 comments older than 15m0s
I0419 16:20:13.714603  976723 comments.go:122] Refreshed 0 comments older than 15m0s

which should not happen. Also occurs in wait.Forever.

I suspect that fc8a39d439ea08b006fb7ea1db1058175cc7adf5 in https://github.com/kubernetes/kubernetes/pull/87829 regressed this as that was the most recent major update and I only started seeing this on a recent apimachinery bump.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 17 (17 by maintainers)

Most upvoted comments

I do not have a PR open