Skip to content

Commit

Permalink
beater: don't hang if runServer returns error
Browse files Browse the repository at this point in the history
If runServer returns an error without Stop being
called, signal the "done" channel.
  • Loading branch information
axw committed Feb 15, 2021
1 parent 120d284 commit 453e76c
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion beater/beater.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,12 @@ func (bt *beater) start(ctx context.Context, cancelContext context.CancelFunc, b
if err != nil {
return nil, err
}
bt.stopServer = func() {
go func() {
defer close(done)
defer closeTracer()
s.Wait()
}()
bt.stopServer = func() {
if bt.config.ShutdownTimeout > 0 {
time.AfterFunc(bt.config.ShutdownTimeout, cancelContext)
}
Expand Down Expand Up @@ -316,11 +319,18 @@ func (s *serverRunner) String() string {
return "APMServer"
}

// Stop stops the server.
func (s *serverRunner) Stop() {
s.stopOnce.Do(s.cancelRunServerContext)
s.Wait()
}

// Wait waits for the server to stop.
func (s *serverRunner) Wait() {
s.wg.Wait()
}

// Start starts the server.
func (s *serverRunner) Start() {
s.wg.Add(1)
go func() {
Expand Down

0 comments on commit 453e76c

Please sign in to comment.