Skip to content

fix(rados): list objects a page at a time - #6

Merged
AlexanderSlaa merged 2 commits into
SourceRegistry:mainfrom
wido:fix/stream-object-listing
Nov 21, 2026
Merged

AlexanderSlaa merged 2 commits into
SourceRegistry:mainfrom
wido:fix/stream-object-listing

Conversation

@wido

@wido wido commented Oct 27, 2026

Copy link
Copy Markdown
Contributor

IoContext.objects() is an async generator, but it got its entries from one native call. That call read the whole listing into memory on the thread pool and converted all of it to JavaScript at once. For a pool with millions of objects, every name is in memory twice, and the first entry only arrives after the whole pool has been listed.

The listing is now a native handle that reads one page per call. objects() yields each page as it arrives. The page size is set with {pageSize} and defaults to 1024. The listing is closed when the loop ends, also when the caller leaves it early. While a listing is open, its io context can't be destroyed, the same as with a watch.

The integration test lists 25 objects in pages of 4. It also leaves a listing early, which would make the io context's close fail with EBUSY if the listing weren't closed.

@AlexanderSlaa AlexanderSlaa left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for your contribution!

Verified:

  • 2500 objects are each listed exactly once with the default page size and with page sizes 1, 7, 2500 and 10000;
  • an empty namespace lists nothing;
  • pageSize: 0 rejects with RangeError, and the listing is still closed;
  • two listings of one io context run side by side;
  • an open listing makes io.close() fail with EBUSY, and leaving the loop releases it;
  • an abandoned listing is closed when it is garbage collected.

Two notes:

  1. With #2: the listing is opened lazily in the first next() on the thread pool, so it uses the namespace at that moment, not at objects(). Once #2 is in, an open listing should count as in flight, the same as a watch, or setNamespace between objects() and the first page changes what gets listed. This also conflicts with #2 in io_context.cpp.
  2. Minor: if the wrapper is garbage collected while a page is being read, ~ObjectListWrap calls close() on the main thread and waits on data->mutex until that page finishes. That's rare and short, but it does block the event loop.

wido and others added 2 commits November 21, 2026 22:37
IoContext.objects() is an async generator, but it got its entries from one
native call that read the whole listing into a vector on the thread pool and
converted all of it to JavaScript at once. For a pool with millions of objects
that holds every name in memory twice and keeps a thread busy for the whole
listing before the first entry is yielded.

The listing is now a native handle that reads a page of entries per call
(pageSize, 1024 by default). objects() yields each page as it arrives and
closes the listing when the loop ends, also when the caller leaves it early.
An open listing keeps its io context from being destroyed, like a watch.
A listing reads the io context's namespace when its first page is read,
so setNamespace() between objects() and that page changed what was
listed. An open listing now blocks the setters with EBUSY, the same as a
registered watch.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@AlexanderSlaa
AlexanderSlaa force-pushed the fix/stream-object-listing branch from 71499e7 to d28ce0d Compare November 21, 2026 21:38
@AlexanderSlaa
AlexanderSlaa merged commit 61d68c9 into SourceRegistry:main Nov 21, 2026
9 checks passed
github-actions Bot pushed a commit that referenced this pull request Nov 21, 2026
## [1.1.1](v1.1.0...v1.1.1) (2026-11-21)

### Bug Fixes

* **rados:** list objects a page at a time ([#6](#6)) ([61d68c9](61d68c9))
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 1.1.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

@AlexanderSlaa

Copy link
Copy Markdown
Contributor

Thanks for your contribution! Merged.

#2 landed first, so I rebased this onto main and added one commit on top, d28ce0d fix(rados): count an open object listing as in flight:

  • The listing reads the namespace when its first page is read, so setNamespace() between objects() and that page changed what got listed.
  • An open listing now counts as in flight, like a registered watch. The setters refuse with EBUSY until the listing is closed.
  • Added an assertion for this to your test, and updated the README sentence from fix(rados): refuse io context setting changes while operations are in flight #2.

Your commit is unchanged apart from the conflict resolution: ListObjects is removed in favour of OpenObjectList, and both tests are kept.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants