diff --git a/tap_aggregator/Cargo.toml b/tap_aggregator/Cargo.toml index d36609ad..f464a772 100644 --- a/tap_aggregator/Cargo.toml +++ b/tap_aggregator/Cargo.toml @@ -32,7 +32,7 @@ tap_graph.workspace = true thegraph-core = { workspace = true, features = ["alloy-eip712"] } tokio.workspace = true tonic.workspace = true -tower.workspace = true +tower = { workspace = true, features = ["util", "steer", "limit"] } tracing-subscriber.workspace = true [build-dependencies] diff --git a/tap_aggregator/src/server.rs b/tap_aggregator/src/server.rs index c210560e..8499b2d8 100644 --- a/tap_aggregator/src/server.rs +++ b/tap_aggregator/src/server.rs @@ -378,8 +378,14 @@ pub async fn run_server( let grpc_service = create_grpc_service(rpc_impl)?; + let grpc_router = Router::new() + .layer(tower::limit::ConcurrencyLimitLayer::new( + max_concurrent_connections as usize, + )) + .merge(grpc_service.into_axum_router()); + let service = tower::steer::Steer::new( - [json_rpc_router, grpc_service.into_axum_router()], + [json_rpc_router, grpc_router], |req: &hyper::Request<_>, _services: &[_]| { if req .headers()