Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

feat(personhog): cap router connection age so new pods take traffic (#117350)

Nick Best6c9a2684471a
diff --git a/rust/personhog-router/src/config.rs b/rust/personhog-router/src/config.rs
index 00307fb7b5bb..5dbd5bdcb654 100644
--- a/rust/personhog-router/src/config.rs
+++ b/rust/personhog-router/src/config.rs
@@ -177,6 +177,10 @@ pub struct Config {
#[envconfig(default = "10")]
pub grpc_keepalive_timeout_secs: u64,
+ /// Maximum age of an inbound gRPC connection before a graceful GOAWAY (0 = disabled)
+ #[envconfig(default = "300")]
+ pub grpc_max_connection_age_secs: u64,
+
/// Interval between HTTP/2 keepalive pings sent to the replica backend (0 = disabled)
#[envconfig(default = "30")]
pub backend_keepalive_interval_secs: u64,
@@ -765,6 +769,14 @@ impl Config {
}
}
+ pub fn grpc_max_connection_age(&self) -> Option<Duration> {
+ if self.grpc_max_connection_age_secs == 0 {
+ None
+ } else {
+ Some(Duration::from_secs(self.grpc_max_connection_age_secs))
+ }
+ }
+
pub fn backend_keepalive_interval(&self) -> Option<Duration> {
if self.backend_keepalive_interval_secs == 0 {
None
diff --git a/rust/personhog-router/src/main.rs b/rust/personhog-router/src/main.rs
index f195f8f8c571..6aefb619af9a 100644
--- a/rust/personhog-router/src/main.rs
+++ b/rust/personhog-router/src/main.rs
@@ -394,6 +394,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let grpc_addr = config.grpc_address;
let keepalive_interval = config.grpc_keepalive_interval();
let keepalive_timeout = config.grpc_keepalive_timeout();
+ let max_connection_age = config.grpc_max_connection_age();
let http2_windows = config.grpc_http2_windows();
let max_recv = config.grpc_max_recv_message_size;
let retry_config = config.retry_config();
@@ -418,11 +419,15 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
max_recv,
config.response_size_warn_bytes,
);
- let server = Server::builder()
- .http2_keepalive_interval(keepalive_interval)
- .http2_keepalive_timeout(keepalive_timeout);
- let result = http2_windows
- .apply_to_server(server)
+ let mut server = http2_windows.apply_to_server(
+ Server::builder()
+ .http2_keepalive_interval(keepalive_interval)
+ .http2_keepalive_timeout(keepalive_timeout),
+ );
+ if let Some(age) = max_connection_age {
+ server = server.max_connection_age(age);
+ }
+ let result = server
.layer(GrpcMetricsLayer::default())
.add_service(proxy.clone())
.add_service(IdentityProxyService(proxy.clone()))