Skip to content

Commit dcf12fe

Browse files
authored
feat(rpc): add stream and keepalive limits to indexer gRPC server (#10980)
2 parents 1f55db2 + 2fb7c22 commit dcf12fe

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

zebra-rpc/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Changed
11+
12+
- The indexer gRPC server now bounds concurrent HTTP/2 streams per connection (20)
13+
and closes dead connections via HTTP/2 keepalive pings (30s interval, 10s timeout)
14+
([#10980](https://github.com/ZcashFoundation/zebra/pull/10980)).
15+
1016
### Fixed
1117

1218
- Clarified the error message returned by `getrawtransaction` for transactions

zebra-rpc/src/indexer/server.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! A tonic RPC server for Zebra's indexer API.
22
3-
use std::net::SocketAddr;
3+
use std::{net::SocketAddr, time::Duration};
44

55
use tokio::task::JoinHandle;
66
use tonic::transport::{server::TcpIncoming, Server};
@@ -11,6 +11,19 @@ use zebra_state::ReadState;
1111

1212
use crate::{indexer::indexer_server::IndexerServer, server::OPENED_RPC_ENDPOINT_MSG};
1313

14+
/// Maximum concurrent HTTP/2 streams per connection.
15+
///
16+
/// The primary clients (Zaino and Zallet) each open 1-2 streams via
17+
/// `init_read_state_with_syncer`. 20 provides generous headroom while
18+
/// bounding resource usage from untrusted clients.
19+
const MAX_CONCURRENT_STREAMS: u32 = 20;
20+
21+
/// Interval between HTTP/2 keepalive pings sent to detect dead connections.
22+
const HTTP2_KEEPALIVE_INTERVAL: Duration = Duration::from_secs(30);
23+
24+
/// Timeout for HTTP/2 keepalive pings before the connection is closed.
25+
const HTTP2_KEEPALIVE_TIMEOUT: Duration = Duration::from_secs(10);
26+
1427
type ServerTask = JoinHandle<Result<(), BoxError>>;
1528

1629
/// Indexer RPC service.
@@ -56,6 +69,9 @@ where
5669

5770
let server_task: JoinHandle<Result<(), BoxError>> = tokio::spawn(async move {
5871
Server::builder()
72+
.max_concurrent_streams(Some(MAX_CONCURRENT_STREAMS))
73+
.http2_keepalive_interval(Some(HTTP2_KEEPALIVE_INTERVAL))
74+
.http2_keepalive_timeout(Some(HTTP2_KEEPALIVE_TIMEOUT))
5975
.add_service(reflection_service)
6076
.add_service(IndexerServer::new(indexer_service))
6177
.serve_with_incoming(TcpIncoming::from(tcp_listener))

0 commit comments

Comments
 (0)