Skip to content

Commit

Permalink
fix: add validation that NumGrpcChannels requires ForceNewChannel
Browse files Browse the repository at this point in the history
  • Loading branch information
cprice404 committed Jun 5, 2023
1 parent 0e6ffd2 commit f649c7d
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/Cache/CacheClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
use Momento\Cache\CacheOperationTypes\CreateCacheResponse;
use Momento\Cache\CacheOperationTypes\DeleteCacheResponse;
use Momento\Cache\CacheOperationTypes\ListCachesResponse;
use Momento\Cache\Errors\InvalidArgumentError;
use Momento\Cache\Internal\IdleDataClientWrapper;
use Momento\Cache\Internal\ScsControlClient;
use Momento\Cache\Internal\ScsDataClient;
Expand Down Expand Up @@ -83,7 +84,13 @@ public function __construct(
);
};
$this->dataClients = [];
for ($i = 0; $i < $configuration->getTransportStrategy()->getGrpcConfig()->getNumGrpcChannels(); $i++) {

$numGrpcChannels = $configuration->getTransportStrategy()->getGrpcConfig()->getNumGrpcChannels();
$forceNewChannels = $configuration->getTransportStrategy()->getGrpcConfig()->getForceNewChannel();
if (($numGrpcChannels > 0) && (! $forceNewChannels)) {
throw new InvalidArgumentError("When setting NumGrpcChannels > 1, you must also set ForceNewChannel to true, or else the gRPC library will re-use the same channel.");
}
for ($i = 0; $i < $numGrpcChannels; $i++) {
array_push($this->dataClients, new IdleDataClientWrapper($dataClientFactory, $this->configuration));
}
}
Expand Down

0 comments on commit f649c7d

Please sign in to comment.