Skip to content

fix: preserve session lifetime when stopping and moving batch guards - #820

Closed
huhumeng2 wants to merge 1 commit into
eclipse-zenoh:mainfrom
huhumeng2:fix/batch-guard-session-lifetime
Closed

huhumeng2 wants to merge 1 commit into
eclipse-zenoh:mainfrom
huhumeng2:fix/batch-guard-session-lifetime

Conversation

@huhumeng2

@huhumeng2 huhumeng2 commented Oct 8, 2026 •

Copy link
Copy Markdown

Dropping a Session::BatchGuard currently calls z_session_drop, which explicitly closes the shared session even though the guard only cloned its reference. A second batch can therefore start successfully but its publisher subsequently fails with Z_ERR_SESSION_CLOSED.

Release the guard's reference with _z_session_rc_drop after stopping the batch. Also implement ownership-transferring move operations: the default moves copy the C handle without invalidating the source, and move assignment overwrites the destination's previous reference without stopping its batch.

Add a router-free regression test using isolated loopback TCP session pairs. It covers repeated batches with explicit flush and destructor flush, publishing and declaring a publisher after a batch, move construction, move assignment over an active guard, self-move assignment, and a failed nested start leaving the original batch active.

Related: eclipse-zenoh/zenoh-pico#1315. This addresses the C++ guard lifetime and repeated-batch failure; the separately reported declaration failure during an active batch is not covered by this change.

Validation on Ubuntu 22.04, GCC 11, zenoh-pico d9b4eea486ea90bbeb61dd59cace7bac54a18562:

  • New regression test fails on unchanged zenoh-cpp 2fafc38700d256335c1b4f76b3212c42cc70b8c1: assert(!session.is_closed()) after the first batch.
  • All zenoh-pico C++ test targets build; the new test and six existing non-router tests pass (7/7).
  • New regression passes 20 consecutive runs.
  • AddressSanitizer with leak detection passes, with both zenoh-pico and the C++ regression instrumented.
  • Strict warning target and clang-format checks pass.
  • A separate UBSan attempt stops in pre-existing zenoh-pico protocol/iobuf.h:91 code (null pointer passed as argument 2); UBSan is not claimed clean.

The contributor ECA check has passed.

@huhumeng2 huhumeng2 closed this Oct 9, 2026
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