Skip to content

Commit

Permalink
call metrics context cancel on all paths
Browse files Browse the repository at this point in the history
  • Loading branch information
janezpodhostnik committed Feb 19, 2025
1 parent 03790ff commit d48c663
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion bootstrap/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -702,27 +702,32 @@ func (m *metricsWrapper) Start(ctx context.Context) error {
m.log.Info().Msg("bootstrap starting metrics server")

ctx, cancel := context.WithCancel(ctx)
m.stopFN = cancel
ictx, errCh := irrecoverable.WithSignaler(ctx)

m.Server.Start(ictx)
if err := util.WaitClosed(ctx, m.Ready()); err != nil {
cancel()
return fmt.Errorf("failed to start metrics server: %w", err)
}
select {
case err := <-errCh:
// there might be an error already if the startup failed
cancel()
return err
default:
}

go func() {
err := <-errCh
cancel()
if err != nil {
m.log.Err(err).Msg("error in metrics server")
panic(err)
}
}()

m.stopFN = cancel

return nil
}

Expand Down

0 comments on commit d48c663

Please sign in to comment.