minio / minio-js

MinIO Client SDK for Javascript
https://docs.min.io/docs/javascript-client-quickstart-guide.html
Apache License 2.0
920 stars 271 forks source link

`ListObjectsV2` command returns `IsTruncated: true` even if there are no more objects to list #1314

Closed benterris closed 1 month ago

benterris commented 1 month ago

We're using the ListObjectsV2 command to list objects in a large folder. To do this we set a MaxKeys value, and receive the list of objects by batch. Each command result has either isTruncated: true (which means there are more objects to be listed), or either isTruncated: false (which means we are done). For some values of MaxKeys however, we can receive isTruncated: true while all objects have been listed already.

Expected behavior

We create a minio bucket with 3 objects and use ListObjectV2 command to list objects in this bucket, with MaxKeys = 1 , and use the continuation token to retrieve the full content.

We should receive 3 batches of 1 object, with the last batch having isTruncated: true.

Current Behavior

We receive 3 batches of 1 object, and 1 batch of 0 objects. The last non-empty batch has isTruncated: false even though we're done listing. This does not happen with MaxKeys >= 2 in this case, but we've seen this happen in production with other values of MaxKeys and a greater number of objects.

Steps to Reproduce

Create a minio bucket and upload 3 objects. Run the following code:

async function logAllObjects() {
    const s3Client = new S3Client(
        //...
    )
    let commandOutput = undefined;
    do {
        commandOutput = await s3Client.send(new ListObjectsV2Command({
            Bucket: 'someBucketName',
            MaxKeys: 1,
            Prefix: 'somePrefix',
            ContinuationToken: commandOutput ? commandOutput.NextContinuationToken : undefined,
        }));
        if (!commandOutput.Contents) {
            throw new Error('Unless the bucket is empty, this should never happen')  
        }
        console.log(commandOutput.Contents)
    } while (commandOutput.IsTruncated);
}
logAllObjects();

The error will be thrown.

Your Environment

We're using minio-js v8.0.0, and the minio image docker.io/bitnami/minio:2024.6.13-debian-12-r2

prakashsvmx commented 1 month ago
  1. Please use MinIO official images (bitnami is not supported by us)
  2. Please share mc admin trace -v for all the scenarios described for investigation.
prakashsvmx commented 1 month ago

The code is not using minio-js sdk. looks like using aws sdk js. Please reach out to the respective forum. @benterris

there is no constructor named as referenced in the above piece of code.

new S3Client(

new ListObjectsV2Command

prakashsvmx commented 1 month ago

If you are using minio in production please consider https://min.io/pricing for valid subscription and direct engineering support.