Fix S3 lookup unbounded pagination with double call#6851
Merged
pditommaso merged 3 commits intomasterfrom Feb 23, 2026
Merged
Conversation
The lookup method paginated through all objects under an S3 prefix (maxKeys=250) to check path existence. On prefixes with millions of objects this caused the main thread to hang for minutes parsing massive XML responses. Observed in production: nf-schema parameter validation calls Files.exists() on an S3 outdir path, which triggers S3ObjectSummaryLookup.lookup. With a large prefix like s3://bucket/results containing many objects from previous runs, the pagination loop iterated indefinitely. Fix: use maxKeys=2 and remove pagination. The matchName check only needs to find the exact key or its first child (key + "/"), which are guaranteed to appear in the first results due to S3 lexicographic ordering. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Signed-off-by: Paolo Di Tommaso <paolo.ditommaso@gmail.com>
…refix and smaller lexico order characters than / Signed-off-by: jorgee <jorge.ejarque@seqera.io>
✅ Deploy Preview for nextflow-docs-staging canceled.
|
2 tasks
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Signed-off-by: Paolo Di Tommaso <paolo.ditommaso@gmail.com>
pditommaso
approved these changes
Feb 20, 2026
Member
pditommaso
left a comment
There was a problem hiding this comment.
Well done. Considering is really a tricky issue, I took the liberty to extend the docs/comment
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
S3ObjectSummaryLookup.lookup()used an unboundedwhile(true)pagination loop that iterated through all objects sharing a given prefix (fetching 250 keys per page). On S3 buckets with large prefixes containing millions of objects, this caused excessive LIST API calls, high latency, and potential timeouts — just to check whether a single path exists.Solution
Replace the unbounded loop with at most two bounded
listObjectscalls:Call 1 —
prefix(key),maxKeys(2): covers the common cases where the exact key or its first directory child appears within the first 2 lexicographic results.Call 2 (fallback) —
prefix(key + "/"),maxKeys(1): needed because S3 lists keys in lexicographic (UTF-8 byte) order, and characters like-(0x2D) and.(0x2E) sort before/(0x2F). This means sibling keys such asa-a/anda.txtappear beforea/in the listing, potentially pushing the directory child outside Call 1's result window. Call 2 searches with prefixkey/directly, bypassing those siblings.Example of the lexicographic ordering issue
Given keys
a-a/file-3,a.txt, anda/file-1, S3 returns them as:With
maxKeys(2), Call 1 only seesa-a/file-3anda.txt— neither matches. Call 2 with prefixa/findsa/file-1, confirming thatais a directory.Alternative to #6849