Skip to content

Commit

Permalink
chore: validate num_channels when building client
Browse files Browse the repository at this point in the history
  • Loading branch information
cprice404 committed Oct 9, 2024
1 parent 9612858 commit c90273f
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions sdk/src/config/grpc_configuration.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use std::time::Duration;

const MAX_NUM_CHANNELS: usize = 200;

/// Low-level gRPC settings for communicating with Momento.
#[derive(Clone, Debug)]
pub struct GrpcConfiguration {
Expand Down Expand Up @@ -114,6 +116,13 @@ impl GrpcConfigurationBuilder<ReadyToBuild> {

/// Constructs the GrpcConfiguration with the given settings.
pub fn build(self) -> GrpcConfiguration {
let num_channels = self.0.num_channels;
if num_channels == 0 || num_channels > MAX_NUM_CHANNELS {
panic!(
"The maximum number of grpc channels (connections must be between 1 and {}",
MAX_NUM_CHANNELS
);
}
GrpcConfiguration {
deadline: self.0.deadline,
num_channels: self.0.num_channels,
Expand Down

0 comments on commit c90273f

Please sign in to comment.