Skip to content

Session.undeclare: detach the key-expr handle even when undeclare fails#491

Merged
milyin merged 2 commits into
zenoh-flat-transitionfrom
fix-undeclare-consumed-handle
Jul 17, 2026
Merged

Session.undeclare: detach the key-expr handle even when undeclare fails#491
milyin merged 2 commits into
zenoh-flat-transitionfrom
fix-undeclare-consumed-handle

Conversation

@milyin

@milyin milyin commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

The generated undeclareKeyexpr wrapper consumes the key-expr handle even when the native undeclare fails (the Rust side takes it by value — finally { keyExpr.markConsumed() } in the generated code). Session.undeclare cleared keyExpr.handle only after a successful call, so on failure a dead (consumed) handle stayed attached: every later operation on that KeyExpr selected the closed handle and failed with "Operation on a closed native handle" instead of degrading to the string form, as the ownership model promises.

Detach the handle in a finally so the KeyExpr degrades to string-backed either way. Regression test: declaring on one session and undeclaring through another makes the native undeclare fail; the test asserts the handle is detached and string-backed operations (algebra, put) keep working.

Found by review on the zenoh-kotlin port (eclipse-zenoh/zenoh-kotlin#668), which had inherited the same pattern and is fixed there identically.

KeyExprHandleTest: 4/4 green.

🤖 Generated with Claude Code

milyin and others added 2 commits July 17, 2026 23:28
The generated wrapper consumes the handle even when the native undeclare
errors (the Rust side takes it by value). Clearing keyExpr.handle only after
a successful call left a dead handle attached on failure: every later
operation selected the closed handle and failed instead of degrading to the
string form. Detach in a finally; regression-tested by undeclaring through
the wrong session.

Found while porting zenoh-kotlin (eclipse-zenoh/zenoh-kotlin#668), which had
inherited the same pattern.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@milyin
milyin merged commit ea88bf1 into zenoh-flat-transition Jul 17, 2026
13 checks passed
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.

1 participant