You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
daemon: add configurable max-age to recycle RPC connections
Long-lived daemon RPC connections stay pinned to a single backend for
their whole lifetime. When electrs connects through a load balancer such
as a Kubernetes ClusterSetIP (`*.clusterset.local`), a connection
established before a node rotation keeps routing to the original backend
via the existing TCP/conntrack flow, even after healthier/closer
backends become available. The connection is only re-established on
error, so a still-working-but-stale endpoint is never rebalanced.
Add a `--daemon-rpc-conn-max-age` option (seconds). When a connection
exceeds the configured age it is proactively recycled before the next
request, re-establishing the TCP connection so the load balancer can
re-select a backend. Defaults to 0 = unlimited (never recycle), so
behavior is unchanged unless explicitly enabled. The age check is also
applied to the per-thread connections used for parallel RPC requests.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Copy file name to clipboardExpand all lines: src/config.rs
+19Lines changed: 19 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -5,6 +5,7 @@ use std::net::SocketAddr;
5
5
use std::net::ToSocketAddrs;
6
6
use std::path::{Path,PathBuf};
7
7
use std::sync::Arc;
8
+
use std::time::Duration;
8
9
use stderrlog;
9
10
10
11
usecrate::chain::Network;
@@ -27,6 +28,7 @@ pub struct Config {
27
28
pubdaemon_rpc_addr:SocketAddr,
28
29
pubdaemon_rpc_fallback_addr:Option<SocketAddr>,
29
30
pubdaemon_parallelism:usize,
31
+
pubdaemon_conn_max_age:Option<Duration>,
30
32
pubcookie:Option<String>,
31
33
pubelectrum_rpc_addr:SocketAddr,
32
34
pubhttp_addr:SocketAddr,
@@ -177,6 +179,13 @@ impl Config {
177
179
.help("Number of JSONRPC requests to send in parallel")
178
180
.default_value("4")
179
181
)
182
+
.arg(
183
+
Arg::with_name("daemon_rpc_conn_max_age")
184
+
.long("daemon-rpc-conn-max-age")
185
+
.help("Max age (in seconds) of a daemon RPC TCP connection before it is proactively recycled. Recycling re-establishes the connection, letting a load balancer (e.g. a Kubernetes ClusterSetIP) re-select a backend after node rotations. 0 = unlimited / never recycle (default)")
0 commit comments