Skip to content

Commit 867065c

Browse files
commit
1 parent 9fbfd70 commit 867065c

File tree

2 files changed

+10
-12
lines changed

2 files changed

+10
-12
lines changed

src/Ydb.Sdk/src/DriverConfig.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ public class DriverConfig
99
public string Database { get; }
1010
public ICredentialsProvider Credentials { get; }
1111

12-
public TimeSpan KeepAlivePingDelay { get; set; } = TimeSpan.FromSeconds(10);
13-
1412
internal X509Certificate2Collection CustomServerCertificates { get; } = new();
1513
internal TimeSpan EndpointDiscoveryInterval = TimeSpan.FromMinutes(1);
1614
internal TimeSpan EndpointDiscoveryTimeout = TimeSpan.FromSeconds(10);

src/Ydb.Sdk/src/Pool/ChannelPool.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -75,17 +75,17 @@ public interface IChannelFactory<out T> where T : ChannelBase, IDisposable
7575

7676
internal class GrpcChannelFactory : IChannelFactory<GrpcChannel>
7777
{
78+
private const int KeepAlivePingDelaySeconds = 10;
79+
7880
private readonly ILoggerFactory _loggerFactory;
7981
private readonly ILogger<GrpcChannelFactory> _logger;
80-
private readonly DriverConfig _config;
81-
82-
private X509Certificate2Collection ServerCertificates => _config.CustomServerCertificates;
82+
private readonly X509Certificate2Collection _x509Certificate2Collection;
8383

8484
internal GrpcChannelFactory(ILoggerFactory loggerFactory, DriverConfig config)
8585
{
8686
_loggerFactory = loggerFactory;
8787
_logger = loggerFactory.CreateLogger<GrpcChannelFactory>();
88-
_config = config;
88+
_x509Certificate2Collection = config.CustomServerCertificates;
8989
}
9090

9191
public GrpcChannel CreateChannel(string endpoint)
@@ -99,7 +99,7 @@ public GrpcChannel CreateChannel(string endpoint)
9999

100100
var httpHandler = new SocketsHttpHandler
101101
{
102-
KeepAlivePingDelay = _config.KeepAlivePingDelay
102+
KeepAlivePingDelay = TimeSpan.FromSeconds(KeepAlivePingDelaySeconds)
103103
};
104104

105105
// https://github.com/grpc/grpc-dotnet/issues/2312#issuecomment-1790661801
@@ -108,7 +108,7 @@ public GrpcChannel CreateChannel(string endpoint)
108108
channelOptions.HttpHandler = httpHandler;
109109
channelOptions.DisposeHttpClient = true;
110110

111-
if (ServerCertificates.Count == 0)
111+
if (_x509Certificate2Collection.Count == 0)
112112
{
113113
return GrpcChannel.ForAddress(endpoint, channelOptions);
114114
}
@@ -129,11 +129,11 @@ public GrpcChannel CreateChannel(string endpoint)
129129
try
130130
{
131131
chain.ChainPolicy.VerificationFlags = X509VerificationFlags.AllowUnknownCertificateAuthority;
132-
chain.ChainPolicy.ExtraStore.AddRange(ServerCertificates);
132+
chain.ChainPolicy.ExtraStore.AddRange(_x509Certificate2Collection);
133133

134-
return chain.Build(new X509Certificate2(certificate))
135-
&& chain.ChainElements.Any(chainElement => ServerCertificates.Any(trustedCert =>
136-
chainElement.Certificate.Thumbprint == trustedCert.Thumbprint));
134+
return chain.Build(new X509Certificate2(certificate)) && chain.ChainElements.Any(chainElement =>
135+
_x509Certificate2Collection.Any(trustedCert =>
136+
chainElement.Certificate.Thumbprint == trustedCert.Thumbprint));
137137
}
138138
catch (Exception e)
139139
{

0 commit comments

Comments
 (0)