Skip to content

fix(rados): refuse io context setting changes while operations are in flight - #2

Merged
AlexanderSlaa merged 1 commit into
SourceRegistry:mainfrom
wido:fix/io-context-settings-while-busy
Nov 21, 2026
Merged

AlexanderSlaa merged 1 commit into
SourceRegistry:mainfrom
wido:fix/io-context-settings-while-busy

Conversation

@wido

@wido wido commented Oct 27, 2026

Copy link
Copy Markdown
Contributor

An operation reads the namespace, locator key and read snapshot of its io context when it runs on the thread pool, not when it's called. So this reads x from namespace b:

io.setNamespace("a");
const p = io.read("x", 16n);
io.setNamespace("b");
await p;

The setters also change the handle under a shared lock, so they race with the operations running on it.

I hit this against a cluster where the client may only use one namespace. Of 64 reads queued before setNamespace("elsewhere"), 60 failed with EPERM.

With this change, every queued io context and RBD pool operation counts as in flight until it completes. A registered watch counts too, because its acks use the namespace. While anything is in flight, setNamespace(), setLocatorKey() and setReadSnapshot() throw a CephError with errno EBUSY. When nothing is in flight, they change the handle under an exclusive lock. An open RBD image doesn't count, because librbd copies the io context on open.

I added an integration test, which fails on main and passes with this change. The README explains the behaviour and suggests one IoContext per namespace.

… flight

An operation reads the namespace, locator key and read snapshot of its io
context when it runs on the libuv thread pool, not when it is called. So
setNamespace("a"); read(x); setNamespace("b") could read x from namespace b.
The setters also changed the handle under a shared lock, racing with the
operations running on it.

Every queued io context and RBD pool operation, and every registered watch
(its acks use the namespace), now counts as in flight until it completes.
setNamespace(), setLocatorKey() and setReadSnapshot() throw a CephError with
errno EBUSY while any are, and change the handle under an exclusive lock.
An open RBD image does not count: librbd copies the io context on open.

Against a cluster where the client may only use one namespace, 60 of 64 reads
queued before setNamespace("elsewhere") failed with EPERM before this change.

@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 against a single-node Squid cluster (1 mon, 1 memstore OSD).

Reproduced on main: of 64 reads queued before setNamespace("elsewhere"), 60 ran in the wrong namespace and failed with ENOENT. With this PR: 0 of 64 failed, and the setter throws EBUSY.

I also checked that:

  • setNamespace, setLocatorKey and setReadSnapshot refuse while an operation is pending and work again once it settles;
  • rejected operations (ENOENT) and synchronous TypeErrors on arguments don't leave the counter stuck;
  • a namespace set while idle applies to the next operations;
  • RBD pool operations count as in flight, and an open image doesn't;
  • a registered watch blocks the setters until it is closed.

Merge note: #4 (writeOp) and #6 (paged listing) don't use in_flight(). Once this is merged, #4 conflicts only in the README and tests, so WriteOp merges silently without the guard. I built #2 + #4 together: setNamespace() was allowed while 32 writeOps were queued. Whichever of those lands after this one needs in_flight(state_) in WriteOp, and an open object listing should probably count like a watch does.

@AlexanderSlaa
AlexanderSlaa merged commit dd3f83b 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.0](v1.0.3...v1.1.0) (2026-11-21)

### Bug Fixes

* **build:** include <stdexcept> for std::runtime_error ([#1](#1)) ([0d44095](0d44095))
* **rados:** refuse io context setting changes while operations are in flight ([#2](#2)) ([dd3f83b](dd3f83b))

### Features

* name the errno of a CephError in codeName ([#5](#5)) ([ff3568d](ff3568d))
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 1.1.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

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