Skip to content

feat: add close_link method to TransportUnicast API - #2745

Open
gabrik wants to merge 5 commits into
eclipse-zenoh:mainfrom
gabrik:gabrik/transport-close-link
Open

feat: add close_link method to TransportUnicast API#2745
gabrik wants to merge 5 commits into
eclipse-zenoh:mainfrom
gabrik:gabrik/transport-close-link

Conversation

@gabrik

@gabrik gabrik commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

Summary

Add close_link(Link) to the TransportUnicastTrait and expose it through the TransportUnicast public wrapper. This allows closing a specific link within a multilink transport without tearing down the entire transport.

Changes

  • TransportUnicastTrait: new async fn close_link(&self, link: Link) -> ZResult<()> on the trait
  • TransportUnicastUniversal: delegates to existing del_link()
  • TransportUnicastLowlatency: closes the entire transport (it has at most one link)
  • MockTransportUnicastInner: no-op stub for tests
  • TransportUnicast: public close_link() wrapper exposed with doc example

Motivation

This is a prerequisite for transport link rotation (see #2746), where the rotation engine needs to close individual links within a multilink transport during make-before-break cycles. The existing del_link method on TransportUnicastUniversal was pub(crate) and not exposed through the trait or the public wrapper.

Tests

  • transport_unicast_close_link_multilink: closes one of two links, verifies transport survives, then closes the last link and verifies transport closes
  • transport_unicast_close_link_single_link: closes the only link, verifies transport closes

🏷️ Label-Based Checklist

Based on the labels applied to this PR, please complete these additional requirements:

Labels: new feature

🆕 New Feature Requirements

Since this PR adds a new feature:

  • Feature scope documented - Clear description of what the feature does and why it's needed
  • Minimum necessary code - Implementation is as simple as possible, doesn't overcomplicate the system
  • New APIs well-designed - Public APIs are intuitive, consistent with existing APIs
  • Comprehensive tests - All functionality is tested (happy path + edge cases + error cases)
  • Examples provided - Usage examples in code comments or separate example files
  • Documentation added - New docs explaining the feature, its use cases, and API
  • Feature flag considered - Can the feature be enabled/disabled for gradual rollout?
  • Performance impact assessed - Memory, CPU, storage implications measured
  • Integration tested - Feature works with existing features

Consider: Can this feature be split into smaller, incremental PRs?

Instructions:

  1. Check off items as you complete them (change - [ ] to - [x])
  2. The PR checklist CI will verify these are completed

This checklist updates automatically when labels change, but preserves your checked boxes.

Add close_link(Link) to the TransportUnicastTrait and expose it
through the TransportUnicast public wrapper. This allows closing a
specific link within a multilink transport without tearing down
the entire transport.

- TransportUnicastUniversal: delegates to existing del_link()
- TransportUnicastLowlatency: closes the entire transport (it
  has at most one link)
- MockTransportUnicastInner: no-op stub for tests
@gabrik gabrik added enhancement Existing things could work better new feature Something new is needed and removed enhancement Existing things could work better labels Aug 18, 2026
Add two tests for close_link:
- transport_unicast_close_link_multilink: verify that closing one
  of two links keeps the transport alive, then closing the last
  link closes the transport
- transport_unicast_close_link_single_link: verify that closing
  the only link closes the entire transport

Also add a doc example to the close_link method on TransportUnicast.
@gabrik gabrik changed the title transport: add close_link method to TransportUnicast API feat: add close_link method to TransportUnicast API Aug 18, 2026
@codecov

codecov Bot commented Aug 18, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 44.44444% with 10 lines in your changes missing coverage. Please review.
✅ Project coverage is 74.69%. Comparing base (8aaf85c) to head (ed8e049).
⚠️ Report is 2 commits behind head on main.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
io/zenoh-transport/src/unicast/mod.rs 33.33% 8 Missing ⚠️
io/zenoh-transport/src/unicast/test_helpers.rs 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2745      +/-   ##
==========================================
+ Coverage   74.67%   74.69%   +0.01%     
==========================================
  Files         425      419       -6     
  Lines       63930    63837      -93     
==========================================
- Hits        47739    47680      -59     
+ Misses      16191    16157      -34     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

gabrik added 3 commits August 18, 2026 11:54
Add transport_unicast_close_link_lowlatency test that exercises the
close_link path on the lowlatency transport (which has at most one
link, so closing it closes the entire transport). This covers the
previously uncovered close_link implementation in
lowlatency/transport.rs.
The doc test for close_link failed because:
1. .await was used outside an async block
2. TransportUnicast is not exported at crate root

Fix by wrapping the example body in  and using the
full path zenoh_transport::unicast::TransportUnicast.
@gabrik
gabrik requested review from fuzzypixelz and oteffahi and removed request for oteffahi August 20, 2026 14:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

new feature Something new is needed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants