From 309592a8cf98d279e969aa3f92795fd7fc29436a Mon Sep 17 00:00:00 2001 From: Owen Diehl Date: Mon, 2 May 2022 02:36:51 -0400 Subject: [PATCH] ignores reporting cancellations as errors in the usage-reporter module (#6058) --- pkg/usagestats/reporter.go | 11 +++++++++-- pkg/usagestats/reporter_test.go | 4 ++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/pkg/usagestats/reporter.go b/pkg/usagestats/reporter.go index 06a1f95e05..3387e57a8d 100644 --- a/pkg/usagestats/reporter.go +++ b/pkg/usagestats/reporter.go @@ -3,6 +3,7 @@ package usagestats import ( "bytes" "context" + "errors" "flag" "io" "math" @@ -254,7 +255,10 @@ func (rep *Reporter) running(ctx context.Context) error { if rep.cluster == nil { <-ctx.Done() - return ctx.Err() + if err := ctx.Err(); !errors.Is(err, context.Canceled) { + return err + } + return nil } // check every minute if we should report. ticker := time.NewTicker(reportCheckInterval) @@ -281,7 +285,10 @@ func (rep *Reporter) running(ctx context.Context) error { rep.lastReport = next next = next.Add(reportInterval) case <-ctx.Done(): - return ctx.Err() + if err := ctx.Err(); !errors.Is(err, context.Canceled) { + return err + } + return nil } } } diff --git a/pkg/usagestats/reporter_test.go b/pkg/usagestats/reporter_test.go index b5fb7e8ca6..e6a0ed9712 100644 --- a/pkg/usagestats/reporter_test.go +++ b/pkg/usagestats/reporter_test.go @@ -97,7 +97,7 @@ func Test_ReportLoop(t *testing.T) { <-time.After(6*time.Second + (stabilityCheckInterval * time.Duration(stabilityMinimunRequired+1))) cancel() }() - require.Equal(t, context.Canceled, r.running(ctx)) + require.Equal(t, nil, r.running(ctx)) require.GreaterOrEqual(t, totalReport, 5) first := clusterIDs[0] for _, uid := range clusterIDs { @@ -156,5 +156,5 @@ func TestWrongKV(t *testing.T) { <-time.After(1 * time.Second) cancel() }() - require.Equal(t, context.Canceled, r.running(ctx)) + require.Equal(t, nil, r.running(ctx)) }