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

[YUNIKORN-2525] dispatcher.Stop() waits an extra second unnecessarily #811

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions pkg/dispatcher/dispatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
handlers map[EventType]map[string]func(interface{})
running atomic.Value
lock sync.RWMutex
stopped sync.WaitGroup
}

func initDispatcher() {
Expand Down Expand Up @@ -211,6 +212,7 @@
return
}
getDispatcher().stopChan = make(chan struct{})
getDispatcher().stopped.Add(1)
go func() {
for {
select {
Expand All @@ -229,6 +231,7 @@
case <-getDispatcher().stopChan:
log.Log(log.ShimDispatcher).Info("shutting down event channel")
getDispatcher().setRunning(false)
getDispatcher().stopped.Done()
return
}
}
Expand Down Expand Up @@ -257,13 +260,22 @@
}

close(getDispatcher().stopChan)
maxTimeout := 5
for getDispatcher().isRunning() && maxTimeout > 0 {
log.Log(log.ShimDispatcher).Info("waiting for dispatcher to be stopped",
zap.Int("remainingSeconds", maxTimeout))
time.Sleep(1 * time.Second)
maxTimeout--
stopWait := make(chan struct{})

go func() {
defer close(stopWait)
getDispatcher().stopped.Wait()
}()

// wait until the main event loop stops properly
select {
case <-stopWait:
break
case <-time.After(5 * time.Second):
log.Log(log.ShimDispatcher).Info("dispatcher did not stop in time")
break

Check warning on line 276 in pkg/dispatcher/dispatcher.go

View check run for this annotation

Codecov / codecov/patch

pkg/dispatcher/dispatcher.go#L274-L276

Added lines #L274 - L276 were not covered by tests
}

if getDispatcher().isRunning() {
log.Log(log.ShimDispatcher).Warn("dispatcher even processing did not stop properly")
} else {
Expand Down