From 4b4198522dc5a69cfffb04552ac8ea105bd4a14b Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Tue, 27 Jun 2023 12:44:09 +0100 Subject: [PATCH] storj: fix "uplink: too many requests" errors when uploading to the same file Storj has a rate limit of 1 per second when uploading to the same file. This was being tripped by the integration tests. This patch fixes it by detecting the error and sleeping for 1 second before retrying. See: https://github.com/storj/uplink/issues/149 --- backend/storj/fs.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/backend/storj/fs.go b/backend/storj/fs.go index cd36db6f2..6774cc949 100644 --- a/backend/storj/fs.go +++ b/backend/storj/fs.go @@ -589,6 +589,14 @@ func (f *Fs) Put(ctx context.Context, in io.Reader, src fs.ObjectInfo, options . return nil, err } err = fserrors.RetryError(errors.New("bucket was not available, now created, the upload must be retried")) + } else if errors.Is(err, uplink.ErrTooManyRequests) { + // Storj has a rate limit of 1 per second of uploading to the same file. + // This produces ErrTooManyRequests here, so we wait 1 second and retry. + // + // See: https://github.com/storj/uplink/issues/149 + fs.Debugf(f, "uploading too fast - sleeping for 1 second: %v", err) + time.Sleep(time.Second) + err = fserrors.RetryError(err) } return nil, err }