diff --git a/providers/s3/s3.go b/providers/s3/s3.go index 3d9ba213..2f0447a7 100644 --- a/providers/s3/s3.go +++ b/providers/s3/s3.go @@ -15,6 +15,7 @@ import ( "strings" "testing" + "github.com/efficientgo/core/logerrcapture" "github.com/go-kit/log" "github.com/go-kit/log/level" "github.com/minio/minio-go/v7" @@ -437,12 +438,21 @@ func (b *Bucket) getRange(ctx context.Context, name string, off, length int64) ( return nil, err } } + r, err := b.client.GetObject(ctx, b.name, name, *opts) + if err != nil { + return nil, err + } - // StatObject to see if the object exists and we have permissions to read it - if _, err := b.client.StatObject(ctx, b.name, name, *opts); err != nil { + // NotFoundObject error is revealed only after first Read. This does the initial GetRequest. Prefetch this here + // for convenience. + if _, err := r.Read(nil); err != nil { + defer logerrcapture.Do(b.logger, r.Close, "s3 get range obj close") + + // First GET Object request error. return nil, err } - return b.client.GetObject(ctx, b.name, name, *opts) + + return r, nil } // Get returns a reader for the given object name.