From 65a901bb5cce79ed2a02f2674f22bfe85d6de685 Mon Sep 17 00:00:00 2001 From: Liam Stanley Date: Wed, 2 Sep 2020 17:02:45 -0400 Subject: [PATCH] goroutine for context shutdown --- metrics.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/metrics.go b/metrics.go index 08068c6..790c600 100644 --- a/metrics.go +++ b/metrics.go @@ -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) + } + }() }