Skip to content

Commit

Permalink
goroutine for context shutdown
Browse files Browse the repository at this point in the history
  • Loading branch information
lrstanley committed Sep 2, 2020
1 parent c1c2d54 commit 65a901b
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,15 @@ func initMetrics(ctx context.Context, wg *sync.WaitGroup, errors chan<- error, r
}
}()

<-ctx.Done()
go func() {
wg.Add(1)
defer wg.Done()

debug.Printf("requesting metrics server to shutdown")
if err := srv.Shutdown(context.Background()); err != nil && err != http.ErrServerClosed {
errors <- fmt.Errorf("unable to shutdown metrics server: %v", err)
}
<-ctx.Done()

debug.Printf("requesting metrics server to shutdown")
if err := srv.Shutdown(context.Background()); err != nil && err != http.ErrServerClosed {
errors <- fmt.Errorf("unable to shutdown metrics server: %v", err)
}
}()
}

0 comments on commit 65a901b

Please sign in to comment.