Skip to content

fix: bound ListObjectsV2 page size to 100 and raise response-header timeout to 60s - #21

Merged
loverustfs merged 1 commit into
mainfrom
fix/list-timeout-and-pagination
Dec 1, 2026
Merged

loverustfs merged 1 commit into
mainfrom
fix/list-timeout-and-pagination

Conversation

@loverustfs

Copy link
Copy Markdown
Contributor

Problem

When scanning large buckets with deep directory trees on HDD-backed S3-compatible clusters (such as MinIO/Ceph gateways), scan / run / diff could fail midway with:

bucket <name>: list page: operation error S3: ListObjectsV2, exceeded maximum number of attempts, 3, ... net/http: timeout awaiting response headers

Root Causes

  1. Unbounded ListObjectsV2 page size: cluster.WalkObjects did not send MaxKeys, allowing some S3-compatible servers/gateways to default to oversized pages (e.g., 10,000 keys per page), or forcing HDD backends to stat up to 1,000+ objects before sending response headers.
  2. Tight hardcoded 30s response-header timeout: internal/s3client/client.go hardcoded tr.ResponseHeaderTimeout = 30 * time.Second with no configuration override.
  3. Low retry budget & shared client retry quota: AWS SDK Go v2 defaults to 3 attempts and a client-wide 500-token retry bucket (10 tokens per timeout), which can abort long scans or concurrent worker pools during transient storage stalls.
  4. AWS_CA_BUNDLE incompatibility: Passing a raw *http.Client to awsconfig.LoadDefaultConfig broke custom RootCA loading (unable to add custom RootCAs HTTPClient, has no WithTransportOptions, *http.Client).

Changes

  • HDD-friendly bounded ListObjectsV2 pagination (internal/cluster/objects.go, internal/scanner/scanner.go, internal/differ/differ.go):
    • Explicitly send MaxKeys on every ListObjectsV2 request, defaulting to 100 (DefaultListMaxKeys = 100) instead of omitting it or requesting 1,000 keys per page.
    • Configurable (1..1000) via YAML list_max_keys, env LIST_MAX_KEYS, or CLI --list-max-keys.
  • Configurable 60s default response-header timeout (internal/s3client/client.go, internal/config/):
    • Raised default ResponseHeaderTimeout from 30s to 60s (DefaultResponseHeaderTimeout = 60 * time.Second), configurable up to 1h via YAML response_header_timeout, env RESPONSE_HEADER_TIMEOUT, or CLI --response-header-timeout.
    • Scaled blocked read/write I/O watchdog deadline to max(90s, response_header_timeout).
  • Resilient S3 retries (internal/s3client/client.go, internal/config/):
    • Raised CLI default max_attempts from 3 to 5 (1..100), configurable via YAML max_attempts, env MAX_ATTEMPTS (also honoring AWS_MAX_ATTEMPTS), or CLI --max-attempts.
    • Disabled the SDK's shared 500-token client retry quota (ratelimit.None) so sustained transient timeouts across long scans or parallel workers never silently disable retries.
  • Custom CA support (internal/s3client/client.go):
    • Pass awshttp.NewBuildableClient() to awsconfig.LoadDefaultConfig and clone its transport so AWS_CA_BUNDLE / ca_bundle custom RootCAs work cleanly alongside connection pooling, HTTP/1.1, and timeouts.
  • Tests & Documentation:
    • Added pagination support (max-keys / continuation-token) to internal/fakes3.
    • Added unit & CLI regression tests covering default max-keys=100, custom --list-max-keys, 60s default timeout, transient header-timeout retry recovery, sustained retry quota resilience under -race, AWS_CA_BUNDLE TLS verification, and config/env/CLI precedence.
    • Updated config.example.yaml, cmd/helptext.go, docs/DESIGN.md, README.md, README_ZH.md, and docs/MANUAL*.md.

Verification

  • go vet -tags real_s3 ./... — passed
  • go test -race -count=1 ./... — all 10 packages passed
  • python3 -m unittest discover -s scripts -v — 12/12 passed
  • Built native and linux/amd64 static binaries (CGO_ENABLED=0) and verified CLI --help / --version

Copilot AI balanced review requested due to automatic review settings December 1, 2026 05:08
@loverustfs
loverustfs merged commit 6b071bb into main Dec 1, 2026
7 checks passed
@loverustfs
loverustfs deleted the fix/list-timeout-and-pagination branch December 1, 2026 05:13

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

AWS SDK configuration can still reject valid retry overrides or impose the wrong attempt budget, and the quota-disabling regression does not exhaust the default limiter.

3 open issues
What changed in this PR

This PR improves migration reliability on slow S3-compatible storage by bounding object-listing pages and making transport timeouts and retry budgets configurable.

Changes:

  • Defaults listing pages to 100 keys, response-header timeouts to 60 seconds, and CLI requests to 5 attempts, with YAML, environment, and CLI overrides.
  • Disables the shared retry quota and preserves custom CA certificates in pooled HTTP clients.
  • Adds pagination and transport regression coverage and updates configuration documentation.
File Description
README.md Documents new settings and environment variables.
README_ZH.md Updates Chinese configuration guidance.
internal/​scanner/​scanner.go Adds configurable scan page sizes.
internal/​s3client/​timeout_test.go Adds timeout, retry-quota, and custom-CA tests.
internal/​s3client/​client.go Configures timeouts, retries, and CA-aware transport.
internal/​fakes3/​fakes3.go Supports paginated fake S3 listings.
internal/​differ/​differ.go Applies page-size options to diff listings.
internal/​config/​duration.go Adds duration parsing for configuration.
internal/​config/​config.go Adds transport defaults, validation, and overrides.
internal/​config/​config_test.go Tests transport configuration and precedence.
internal/​cluster/​objects.go Bounds every object-listing request.
internal/​cluster/​objects_test.go Checks default and custom listing page sizes.
docs/​MANUAL.md Documents settings and timeout troubleshooting.
docs/​MANUAL_ZH.md Updates Chinese settings and troubleshooting guidance.
docs/​MANUAL_KO.md Updates Korean transport documentation.
docs/​MANUAL_JA.md Updates Japanese transport documentation.
docs/​MANUAL_IT.md Updates Italian transport documentation.
docs/​MANUAL_FR.md Updates French transport documentation.
docs/​MANUAL_ES.md Updates Spanish transport documentation.
docs/​MANUAL_DE.md Updates German transport documentation.
docs/​DESIGN.md Describes pagination and transport behavior.
config.example.yaml Adds annotated transport configuration examples.
cmd/​root.go Wires CLI overrides into clients and listings.
cmd/​helptext.go Documents new flags in bilingual help.
cmd/​help_test.go Checks help includes new tuning options.
cmd/​cli_regression_test.go Tests pagination and slow-listing recovery through CLI commands.

Review effort: Balanced

Comment thread cmd/root.go
SkipSourceFrozenEnv: sourceFrozenSet,
SkipListMaxKeysEnv: listMaxKeysSet,
SkipResponseHeaderTimeoutEnv: headerTimeoutSet,
SkipMaxAttemptsEnv: maxAttemptsSet,
// Disable the SDK's shared 500-token client retry quota so transient
// cluster stalls across concurrent workers or multi-hour scans do not
// exhaust tokens and silently stop retrying later pages/objects.
o.Retryer = retry.NewStandard(func(ro *retry.StandardOptions) {
Comment on lines +173 to +176
// Stall the first attempt of every distinct prefix past the 100ms header
// timeout, and answer the retry immediately. Over 64 logical operations
// (64 * 10 = 640 timeout cost > 500 default SDK quota, 0 refunded), the
// SDK's default retry rate limiter would fail later operations.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants