Skip to content

Commit

Permalink
add persistent goroutine to pullerGroup tomb
Browse files Browse the repository at this point in the history
This avoids runtime panic from calling Go after all goroutines have returned.

Also, we need to kill the pullerGroup tomb in Stop() to tell the pullerGroup
that it's time to shut down.
  • Loading branch information
barrettj12 committed Aug 14, 2023
1 parent 2b4f8eb commit 97e7d94
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions internals/overlord/logstate/gatherer.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ func (g *logGatherer) Stop() {
// Kill the main loop once either:
// - all the pullers are done
// - timeoutMainLoop has passed
g.pullers.tomb.Kill(nil)
select {
case <-g.pullers.Done():
logger.Debugf("gatherer %q: pullers have finished", g.targetName)
Expand Down
2 changes: 1 addition & 1 deletion internals/overlord/logstate/gatherer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func (s *gathererSuite) TestGathererShutdown(c *C) {
}()

select {
case <-time.After(20 * time.Millisecond):
case <-time.After(100 * time.Millisecond):
c.Fatalf("timeout waiting for gatherer to tear down")
case <-hasShutdown:
}
Expand Down
4 changes: 4 additions & 0 deletions internals/overlord/logstate/puller.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ func newPullerGroup(targetName string) *pullerGroup {
targetName: targetName,
pullers: map[string]*logPuller{},
}
pg.tomb.Go(func() error {
<-pg.tomb.Dying()
return nil
})
return pg
}

Expand Down

0 comments on commit 97e7d94

Please sign in to comment.