Skip to content

Commit

Permalink
Engine.Shutdown only waits 5 seconds for active jobs to complete
Browse files Browse the repository at this point in the history
Signed-off-by: Solomon Hykes <[email protected]>
  • Loading branch information
Solomon Hykes committed Aug 6, 2014
1 parent 92105ea commit eb79dc1
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,20 @@ func (eng *Engine) Shutdown() {
// This requires all concurrent calls to check for shutdown, otherwise
// it might cause a race.

// Wait for all jobs to complete
eng.tasks.Wait()
// Wait for all jobs to complete.
// Timeout after 5 seconds.
tasksDone := make(chan struct{})
go func() {
eng.tasks.Wait()
close(tasksDone)
}()
select {
case <-time.After(time.Second * 5):
case <-tasksDone:
}

// Call shutdown handlers, if any.
// Timeout after 15 seconds.
// Timeout after 10 seconds.
var wg sync.WaitGroup
for _, h := range eng.onShutdown {
wg.Add(1)
Expand All @@ -183,7 +192,7 @@ func (eng *Engine) Shutdown() {
close(done)
}()
select {
case <-time.After(time.Second * 15):
case <-time.After(time.Second * 10):
case <-done:
}
return
Expand Down

0 comments on commit eb79dc1

Please sign in to comment.