From aa1f50197a2c8183afb7eff253906ea9df510744 Mon Sep 17 00:00:00 2001 From: Ivan Fraixedes Date: Thu, 18 Aug 2022 20:07:33 +0200 Subject: [PATCH] satellite/metainfo: Don't log error due to ctx cancellation Context cancellation that aborts a non-essential Redis operation must not be logged as an error because the operation is intentionally canceled. We are actually considering them not to be an error in following operation because of the same reason and we return a RPC canceled status code. On the other hand it doesn't make sense to continue if the context is canceled because although this is a non-essential operation if this one is canceled due to the context the next one will be canceled for the same reason, hence, we return earlier. Change-Id: Ib3331975adeb06367d1ea0a578263ef50ae3f079 --- satellite/metainfo/validation.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/satellite/metainfo/validation.go b/satellite/metainfo/validation.go index f7d53f560..dc5d2c8bc 100644 --- a/satellite/metainfo/validation.go +++ b/satellite/metainfo/validation.go @@ -28,9 +28,7 @@ import ( "storj.io/storj/satellite/metabase" ) -var ( - ipRegexp = regexp.MustCompile(`^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$`) -) +var ipRegexp = regexp.MustCompile(`^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$`) func getAPIKey(ctx context.Context, header *pb.RequestHeader) (key *macaroon.APIKey, err error) { defer mon.Task()(&ctx)(&err) @@ -382,6 +380,10 @@ func (endpoint *Endpoint) addSegmentToUploadLimits(ctx context.Context, projectI func (endpoint *Endpoint) addToUploadLimits(ctx context.Context, projectID uuid.UUID, size int64, segmentCount int64) error { if err := endpoint.projectUsage.AddProjectStorageUsage(ctx, projectID, size); err != nil { + if errs2.IsCanceled(err) { + return rpcstatus.Wrap(rpcstatus.Canceled, err) + } + // log it and continue. it's most likely our own fault that we couldn't // track it, and the only thing that will be affected is our per-project // bandwidth and storage limits.