From 4f1a4feb3e3125ae1b2ff1682fb9fa4218f6e4e2 Mon Sep 17 00:00:00 2001 From: Martin Stefcek <35243812+Cifko@users.noreply.github.com> Date: Thu, 11 Aug 2022 10:55:40 +0200 Subject: [PATCH] fix: cap unlimited rpc connection (#4442) Description --- Setting -1 to rpc max count was setting value usize::MAX which is over the actual limit. How Has This Been Tested? --- Manually. --- comms/core/src/protocol/rpc/server/mod.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/comms/core/src/protocol/rpc/server/mod.rs b/comms/core/src/protocol/rpc/server/mod.rs index dcc1e70faa..4b51793009 100644 --- a/comms/core/src/protocol/rpc/server/mod.rs +++ b/comms/core/src/protocol/rpc/server/mod.rs @@ -37,6 +37,7 @@ pub mod mock; mod router; use std::{ borrow::Cow, + cmp, convert::TryFrom, future::Future, io, @@ -175,7 +176,7 @@ impl RpcServerBuilder { } pub fn with_maximum_simultaneous_sessions(mut self, limit: usize) -> Self { - self.maximum_simultaneous_sessions = Some(limit); + self.maximum_simultaneous_sessions = Some(cmp::min(limit, BoundedExecutor::max_theoretical_tasks())); self } @@ -242,6 +243,7 @@ where ) -> Self { Self { executor: match config.maximum_simultaneous_sessions { + Some(usize::MAX) => BoundedExecutor::allow_maximum(), Some(num) => BoundedExecutor::from_current(num), None => BoundedExecutor::allow_maximum(), },