tonic: expose tcp_keepalive_interval and tcp_keepalive_retries options#2472
Merged
tottoto merged 1 commit intohyperium:masterfrom Jan 1, 2026
Merged
Conversation
Add two new configuration methods to the Server builder: - `tcp_keepalive_interval()`: Sets TCP_KEEPINTVL socket option - `tcp_keepalive_retries()`: Sets TCP_KEEPCNT socket option These options were already implemented in TcpIncoming but not exposed through the Server builder API. This change allows users to fine-tune TCP keepalive behavior for scenarios like: - Cloud load balancer idle timeout matching - NAT traversal requirements - Faster dead connection detection The new options default to None (system default) and only take effect when tcp_keepalive() is also configured.
LucioFranco
added a commit
that referenced
this pull request
Jan 28, 2026
# Changelog for v0.14.3 ## Features - Expose `tcp_keepalive_interval` and `tcp_keepalive_retries` options on Server (#2472) - Allow configuration of `max_local_error_reset_streams` on Server (#2437) - Put source error into the `Display` impl of `Status` (#2417) - `Server::default()` now sets `TCP_NODELAY` to true (#2413) ## Bug Fixes - Respect `max_message_size` when decompressing a message (#2484) - Depend on http at least 1.1.0 (#2426) ## Documentation - Fix documentation links for timeout configuration (#2483) - Fix documentation typos and grammar issues in status.rs and codec/mod.rs (#2468) - Fix labels in `Display for Status` (#2414) - Fix features docs in tonic-build and tonic-prost-build (#2434) - Remove redundant word in tonic-build and tonic-prost-build README (#2425)
grembo
pushed a commit
to grembo/tonic
that referenced
this pull request
Feb 3, 2026
… options (hyperium#2472) Add two new configuration methods to the Server builder: - `tcp_keepalive_interval()`: Sets TCP_KEEPINTVL socket option - `tcp_keepalive_retries()`: Sets TCP_KEEPCNT socket option These options were already implemented in TcpIncoming but not exposed through the Server builder API. This change allows users to fine-tune TCP keepalive behavior for scenarios like: - Cloud load balancer idle timeout matching - NAT traversal requirements - Faster dead connection detection The new options default to None (system default) and only take effect when tcp_keepalive() is also configured. ## Motivation `TcpIncoming` already supports `with_keepalive_interval()` and `with_keepalive_retries()`, but these are not exposed through the `Server` builder. Users need fine-grained control over TCP keepalive for cloud LB timeout matching and faster dead connection detection. ## Solution Add `tcp_keepalive_interval()` and `tcp_keepalive_retries()` methods to `Server` builder, passing them through to `TcpIncoming` in `bind_incoming()`. Both default to `None` and only take effect when `tcp_keepalive()` is also set. Tests updated accordingly. Co-authored-by: shenghui kevin <[email protected]>
LucioFranco
pushed a commit
that referenced
this pull request
Feb 13, 2026
… options (#2472) Add two new configuration methods to the Server builder: - `tcp_keepalive_interval()`: Sets TCP_KEEPINTVL socket option - `tcp_keepalive_retries()`: Sets TCP_KEEPCNT socket option These options were already implemented in TcpIncoming but not exposed through the Server builder API. This change allows users to fine-tune TCP keepalive behavior for scenarios like: - Cloud load balancer idle timeout matching - NAT traversal requirements - Faster dead connection detection The new options default to None (system default) and only take effect when tcp_keepalive() is also configured. ## Motivation `TcpIncoming` already supports `with_keepalive_interval()` and `with_keepalive_retries()`, but these are not exposed through the `Server` builder. Users need fine-grained control over TCP keepalive for cloud LB timeout matching and faster dead connection detection. ## Solution Add `tcp_keepalive_interval()` and `tcp_keepalive_retries()` methods to `Server` builder, passing them through to `TcpIncoming` in `bind_incoming()`. Both default to `None` and only take effect when `tcp_keepalive()` is also set. Tests updated accordingly. Co-authored-by: shenghui kevin <[email protected]>
LucioFranco
added a commit
that referenced
this pull request
Feb 13, 2026
- Expose `tcp_keepalive_interval` and `tcp_keepalive_retries` options on Server (#2472) - Allow configuration of `max_local_error_reset_streams` on Server (#2437) - Put source error into the `Display` impl of `Status` (#2417) - `Server::default()` now sets `TCP_NODELAY` to true (#2413) - Respect `max_message_size` when decompressing a message (#2484) - Depend on http at least 1.1.0 (#2426) - Fix documentation links for timeout configuration (#2483) - Fix documentation typos and grammar issues in status.rs and codec/mod.rs (#2468) - Fix labels in `Display for Status` (#2414) - Fix features docs in tonic-build and tonic-prost-build (#2434) - Remove redundant word in tonic-build and tonic-prost-build README (#2425)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add two new configuration methods to the Server builder:
tcp_keepalive_interval(): Sets TCP_KEEPINTVL socket optiontcp_keepalive_retries(): Sets TCP_KEEPCNT socket optionThese options were already implemented in TcpIncoming but not exposed through the Server builder API. This change allows users to fine-tune TCP keepalive behavior for scenarios like:
The new options default to None (system default) and only take effect when tcp_keepalive() is also configured.
Motivation
TcpIncomingalready supportswith_keepalive_interval()andwith_keepalive_retries(), but these are not exposed through theServerbuilder. Users need fine-grained control over TCP keepalive for cloud LB timeout matching and faster dead connection detection.Solution
Add
tcp_keepalive_interval()andtcp_keepalive_retries()methods toServerbuilder, passing them through toTcpIncominginbind_incoming(). Both default toNoneand only take effect whentcp_keepalive()is also set. Tests updated accordingly.