Skip to content

Add 'so_linger' configuration parameter#2547

Open
juanjole wants to merge 3 commits into
eclipse-zenoh:mainfrom
juanjole:1.8.0-so_linger_conf
Open

Add 'so_linger' configuration parameter#2547
juanjole wants to merge 3 commits into
eclipse-zenoh:mainfrom
juanjole:1.8.0-so_linger_conf

Conversation

@juanjole

@juanjole juanjole commented Apr 6, 2026

Copy link
Copy Markdown
Contributor

Description

Adding the 'so_linger' parameter to set the SO_LINGER of the TCP sockets using config files or locator expressions.

What does this PR do?

Making configurable the SO_LINGER parameter for TCP connections, the default value is None.

Why is this change needed?

The current version sets statically the SO_LINGER to 10 seconds.

Related Issues

Motivated by my concern in this Discord thread and related to #2350 issue.


🏷️ Label-Based Checklist

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

Labels: enhancement

✨ Enhancement Requirements

Since this PR enhances existing functionality:

  • Enhancement scope documented - Clear description of what is being improved
  • Minimum necessary code - Implementation is as simple as possible, doesn't overcomplicate the system
  • Backwards compatible - Existing code/APIs still work unchanged
  • No new APIs added - Only improving existing functionality
  • Tests updated - Existing tests pass, new test cases added if needed
  • Performance improvement measured - If applicable, before/after metrics provided
  • Documentation updated - Existing docs updated to reflect improvements
  • User impact documented - How users benefit from this enhancement

Remember: Enhancements should not introduce new APIs or breaking changes.

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.

Copilot AI review requested due to automatic review settings April 6, 2026 11:45

Copilot AI 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.

Pull request overview

Adds a configurable so_linger TCP socket option (via config files and locator parameters) and removes the previously hardcoded linger timeout behavior from the TCP/TLS link implementations.

Changes:

  • Introduces so_linger as a new TCP socket option (TCP_SO_LINGER) and wires it through config inspection + locator parameter parsing.
  • Extends TcpSocketConfig to carry/apply an optional linger timeout.
  • Removes the prior hardcoded *_LINGER_TIMEOUT = 10 constants and the per-link set_linger calls in TCP/TLS unicast setup.

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
io/zenoh-links/zenoh-link-tls/src/utils.rs Adds so_linger propagation into TLS locator parameters and parses it into TcpSocketConfig.
io/zenoh-links/zenoh-link-tls/src/unicast.rs Removes the hardcoded TLS linger set_linger call.
io/zenoh-links/zenoh-link-tls/src/lib.rs Removes the TLS_LINGER_TIMEOUT configurable constant.
io/zenoh-links/zenoh-link-tcp/src/utils.rs Adds so_linger propagation into TCP locator parameters and parses it into TcpLinkConfig/TcpSocketConfig.
io/zenoh-links/zenoh-link-tcp/src/unicast.rs Removes the hardcoded TCP linger set_linger call.
io/zenoh-links/zenoh-link-tcp/src/lib.rs Removes the TCP_LINGER_TIMEOUT configurable constant.
io/zenoh-links/zenoh-link-quic/src/lib.rs Removes unused QUIC linger timeout constant (legacy).
io/zenoh-links/zenoh-link-quic_datagram/src/lib.rs Removes unused QUIC datagram linger timeout constant (legacy).
io/zenoh-link-commons/src/tcp.rs Extends TcpSocketConfig to include/apply optional linger timeout (currently via deprecated Tokio API).
io/zenoh-link-commons/src/lib.rs Adds TCP_SO_LINGER constant and documentation for the option.
DEFAULT_CONFIG.json5 Documents the new so_linger option in the default config template.
commons/zenoh-config/src/lib.rs Adds so_linger: Option<u32> to validated transport link config structs.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +129 to +130
#[allow(deprecated)]
socket.set_linger(Some(std::time::Duration::from_secs(timeout as u64)))?;

Copilot AI Apr 6, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TcpSocket::set_linger is deprecated in Tokio (hence the #[allow(deprecated)]). Since this option is now configurable, it would be better to avoid the deprecated API by setting SO_LINGER via socket2::SockRef (the repo already uses socket2 elsewhere) or by removing linger support entirely per #2350. This avoids relying on an API that may be removed and keeps CI/lints clean without suppressions.

Suggested change
#[allow(deprecated)]
socket.set_linger(Some(std::time::Duration::from_secs(timeout as u64)))?;
socket2::SockRef::from(&socket)
.set_linger(Some(std::time::Duration::from_secs(timeout as u64)))?;

Copilot uses AI. Check for mistakes.
Comment on lines +55 to +56
// The LINGER option causes the shutdown() call to block until (1) all application data is delivered
// to the remote end or (2) a timeout expires. The timeout is expressed in seconds.

Copilot AI Apr 6, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment describing SO_LINGER says it causes the shutdown() call to block. SO_LINGER affects the behavior of close()/dropping the socket (and whether it blocks / sends RST), not shutdown() itself. Please adjust this documentation to avoid misleading users about what this option does.

Suggested change
// The LINGER option causes the shutdown() call to block until (1) all application data is delivered
// to the remote end or (2) a timeout expires. The timeout is expressed in seconds.
// The LINGER option affects the behavior of close()/dropping the socket: it may cause the close
// operation to block until (1) pending application data is delivered to the remote end or
// (2) a timeout expires. The timeout is expressed in seconds.

Copilot uses AI. Check for mistakes.
pub so_sndbuf: Option<u32>,
/// Configure TCP read buffer size
pub so_rcvbuf: Option<u32>,
/// Configure TCP linger timeout

Copilot AI Apr 6, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so_linger is documented here without specifying the unit, but the default config comment indicates seconds. Please clarify the unit in this doc comment (e.g., “seconds”) and, if possible, document any special semantics (e.g., 0 seconds causing an abortive close on many OSes).

Suggested change
/// Configure TCP linger timeout
/// Configure TCP linger timeout in seconds.
/// Setting this to `0` seconds typically requests an abortive close on many OSes.

Copilot uses AI. Check for mistakes.
Comment thread DEFAULT_CONFIG.json5
Comment on lines 710 to +717
/// Optional configuration for TCP system buffers sizes for TLS links
///
/// Configure TCP read buffer size (bytes)
// so_rcvbuf: 123456,
/// Configure TCP write buffer size (bytes)
// so_sndbuf: 123456,
/// Configure TCP linger timeout (seconds)
// so_linger: 10,

Copilot AI Apr 6, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This section header says “Optional configuration for TCP system buffers sizes for TLS links”, but the newly added so_linger is not a buffer size. Consider updating the wording to something like “TCP socket options” to match the parameters listed below.

Copilot uses AI. Check for mistakes.
@codecov

codecov Bot commented Apr 6, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 64.51613% with 11 lines in your changes missing coverage. Please review.
✅ Project coverage is 74.66%. Comparing base (29b3e63) to head (bfe7360).
⚠️ Report is 64 commits behind head on main.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
io/zenoh-links/zenoh-link-tls/src/utils.rs 62.50% 6 Missing ⚠️
io/zenoh-links/zenoh-link-tcp/src/utils.rs 60.00% 4 Missing ⚠️
io/zenoh-link-commons/src/tcp.rs 80.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2547      +/-   ##
==========================================
+ Coverage   72.49%   74.66%   +2.17%     
==========================================
  Files         390      399       +9     
  Lines       63360    59109    -4251     
==========================================
- Hits        45931    44134    -1797     
+ Misses      17429    14975    -2454     

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

@diogomatsubara diogomatsubara added the enhancement Existing things could work better label Apr 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Existing things could work better

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants