Skip to content

C0-12: Paginate ListObjects so directories with more than 1000 entries are not silently truncated #171

Closed

Description

@scttfrdmn

Summary

ListObjects issues a single ListObjectsV2 call and never follows the continuation token. S3 caps a page at 1000 keys, and Readdir requests exactly 1000 — so any directory with more than 1000 entries is silently truncated with no error and no warning. Files that exist are invisible to ls, to find, and to any tool that walks the tree.

Background

ListObjects (internal/storage/s3/backend.go) makes one request and returns what came back. Grep for IsTruncated, NextContinuationToken, and NextMarker across internal/storage/s3/backend.go returns zero hits — there is no pagination loop anywhere in the backend.

The caller sits exactly at the cap:

objects, err := n.fs.backend.ListObjects(ctx, prefix, 1000) // List up to 1000 objects

(internal/fuse/filesystem.go:258)

Requesting 1000 against a 1000-key page limit means the truncation point and the request limit coincide, so the shortfall is indistinguishable from a directory that genuinely has 1000 entries. For research-computing workloads — the stated target for this project — directories of tens of thousands of files are routine, so this is not an edge case.

Second-order consequence for v0.14.0. Rmdir needs an emptiness check, and #163 specifies ListObjects for it. An unpaginated list cannot answer "is this prefix empty" reliably for large prefixes. Fixing pagination here removes a correctness hazard from that work before it starts. The Lookup fallback path (filesystem.go:232) calls ListObjects(ctx, childPath+"/", 1) to test directory existence — that one is correct, since it only needs to know whether at least one key exists.

Implementation

  1. Loop on IsTruncated, threading ContinuationToken from NextContinuationToken, accumulating until either the requested maxKeys is satisfied or S3 reports no more pages. Preserve the existing maxKeys contract: a caller asking for 1 must still cause exactly one request with MaxKeys: 1 and no follow-up.

  2. Treat maxKeys <= 0 as "all keys" and page to exhaustion. Confirm which callers rely on the current semantics before changing the sentinel — audit every ListObjects call site, not just the two in internal/fuse/filesystem.go.

  3. Guard against unbounded memory on a huge prefix. A million-key directory should not be accumulated into one slice silently. Either cap with an explicit error, or add a streaming/callback variant for the walk-everything case and leave the slice-returning form for bounded requests.

  4. In Readdir, stop passing a magic 1000. Pass 0 (all) if the streaming form is used, or a configurable limit with a WARN log when the limit is hit, so truncation is at least observable rather than silent.

Acceptance Criteria

  • Unit test with a mocked paginated response: two pages, IsTruncated: true on the first, and the returned slice contains keys from both pages.

  • Unit test: ListObjects(ctx, prefix, 1) issues exactly one request and returns one key — no regression in the Lookup existence-check path.

  • Integration test creating 1500 objects under one prefix, then asserting ListObjects returns all 1500:

    AWS_PROFILE=aws AWS_REGION=us-west-2 go test -race -tags=integration ./internal/storage/s3/...
  • Live mount: a directory with 1500 files reports 1500 from ls -1 /mnt/objectfs/test/big | wc -l.

  • go test -race ./internal/storage/s3/... ./internal/fuse/... passes; package coverage stays at or above 80%.

Dependencies

None. Should land before #163 (Unlink/Rmdir), whose emptiness check depends on a reliable listing.

Activity

  1. added
    type: bug
    priority: high
    area: s3
    on Jul 30, 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

    area: s3priority: hightype: bug

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions