Wait for work to complete before returning from Run. (#259)

Partially addresses https://github.com/knative/serving/issues/3074
This commit is contained in:
Matt Moore 2019-02-03 09:40:39 -08:00 committed by Knative Prow Robot
parent a118428db1
commit 18a6804326
1 changed files with 5 additions and 0 deletions

View File

@ -19,6 +19,7 @@ package controller
import (
"context"
"fmt"
"sync"
"time"
"go.uber.org/zap"
@ -208,13 +209,17 @@ func (c *Impl) EnqueueKey(key string) {
// work queue and waits for workers to finish processing their current work items.
func (c *Impl) Run(threadiness int, stopCh <-chan struct{}) error {
defer runtime.HandleCrash()
sg := sync.WaitGroup{}
defer sg.Wait()
defer c.WorkQueue.ShutDown()
// Launch workers to process resources that get enqueued to our workqueue.
logger := c.logger
logger.Info("Starting controller and workers")
for i := 0; i < threadiness; i++ {
sg.Add(1)
go func() {
defer sg.Done()
for c.processNextWorkItem() {
}
}()