Skip to content

cloudflare-r2-binding: getKeys and clear ignore objects beyond the first 1000 #880

Open

Description

@Skyost

Environment

  • unstorage 2.0.0-beta.0 (also reproducible on main)
  • Cloudflare Pages / Workers with an R2 binding

Reproduction

await Promise.all(Array.from({ length: 1005 }, (_, i) => storage.setItem(`many:${i}`, "x")));

console.log((await storage.getKeys("many")).length); // 1000 instead of 1005

Calling the driver's clear("many:") with these 1005 keys leaves all of them in the bucket.

Describe the bug

The cloudflare-r2-binding driver silently ignores every object beyond the first 1000 :

  1. getKeys calls R2Bucket.list() only once. R2 returns at most 1000 objects per call and signals the rest with truncated / cursor, which the driver does not follow. Any listing therefore stops at 1000 keys, and so does everything that relies on it (snapshot, the getKeys + removeItem fallbacks, ...).
  2. clear passes all the listed keys to a single R2Bucket.delete(keys) call. R2 accepts at most 1000 keys per bulk delete, so with more keys nothing is deleted.

For comparison, cloudflare-kv-binding already follows the cursor in getKeys.

Additional context

I'm currently working around it with a pnpm patch generated by Claude that does the following in getKeys :

const keys = [];
let cursor;
do {
  const list = await binding.list({ ...(prefix ? { prefix: `${prefix}:` } : {}), ...(cursor ? { cursor } : {}) });
  keys.push(...list.objects.map((obj) => obj.key));
  cursor = list.truncated ? list.cursor : undefined;
} while (cursor);
return keys;

Activity

  1. added
    bug
    on Nov 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions