Add 'so_linger' configuration parameter#2547
Conversation
There was a problem hiding this comment.
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_lingeras a new TCP socket option (TCP_SO_LINGER) and wires it through config inspection + locator parameter parsing. - Extends
TcpSocketConfigto carry/apply an optional linger timeout. - Removes the prior hardcoded
*_LINGER_TIMEOUT = 10constants and the per-linkset_lingercalls 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.
| #[allow(deprecated)] | ||
| socket.set_linger(Some(std::time::Duration::from_secs(timeout as u64)))?; |
There was a problem hiding this comment.
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.
| #[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)))?; |
| // 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. |
There was a problem hiding this comment.
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.
| // 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. |
| pub so_sndbuf: Option<u32>, | ||
| /// Configure TCP read buffer size | ||
| pub so_rcvbuf: Option<u32>, | ||
| /// Configure TCP linger timeout |
There was a problem hiding this comment.
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).
| /// Configure TCP linger timeout | |
| /// Configure TCP linger timeout in seconds. | |
| /// Setting this to `0` seconds typically requests an abortive close on many OSes. |
| /// 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, |
There was a problem hiding this comment.
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.
Codecov Report❌ Patch coverage is 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. |
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:
Remember: Enhancements should not introduce new APIs or breaking changes.
Instructions:
- [ ]to- [x])This checklist updates automatically when labels change, but preserves your checked boxes.