From 9624090a3a0126dbb4fa8c031968089194cae293 Mon Sep 17 00:00:00 2001 From: Mostyn Bramley-Moore Date: Tue, 15 Mar 2022 18:02:43 +0100 Subject: [PATCH] Create and reuse a single errRequestCancelled variable --- cache/disk/findmissing.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/cache/disk/findmissing.go b/cache/disk/findmissing.go index 8cd83abd1..12e942c82 100644 --- a/cache/disk/findmissing.go +++ b/cache/disk/findmissing.go @@ -22,6 +22,8 @@ type proxyCheck struct { var errMissingBlob = errors.New("a blob could not be found") +var errRequestCancelled = status.Error(codes.Canceled, "Request was cancelled") + // Optimised implementation of FindMissingBlobs, which batches local index // lookups and performs concurrent proxy lookups for local cache misses. // Returns a slice with the blobs that are missing from the cache. @@ -71,7 +73,7 @@ func (c *diskCache) findMissingCasBlobsInternal(ctx context.Context, blobs []*pb if cancelledDueToFailFast { return errMissingBlob } - return status.Error(codes.Canceled, "Request was cancelled") + return errRequestCancelled default: } @@ -114,7 +116,7 @@ func (c *diskCache) findMissingCasBlobsInternal(ctx context.Context, blobs []*pb if cancelledDueToFailFast { return errMissingBlob } - return status.Error(codes.Canceled, "Request was cancelled") + return errRequestCancelled default: } @@ -145,7 +147,7 @@ func (c *diskCache) findMissingCasBlobsInternal(ctx context.Context, blobs []*pb if cancelledDueToFailFast { return errMissingBlob } - return status.Error(codes.Canceled, "Request was cancelled") + return errRequestCancelled case <-waitCh: // Everything in the waitgroup has finished. } }