Repository navigation
fix(rados): refuse io context setting changes while operations are in flight - #2
Conversation
… 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
left a comment
There was a problem hiding this comment.
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,setLocatorKeyandsetReadSnapshotrefuse 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.
# [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))
|
🎉 This PR is included in version 1.1.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
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
xfrom namespaceb: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()andsetReadSnapshot()throw aCephErrorwith errnoEBUSY. 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
mainand passes with this change. The README explains the behaviour and suggests oneIoContextper namespace.