@@ -77,13 +77,15 @@ internal class GrpcChannelFactory : IChannelFactory<GrpcChannel>
7777{
7878 private readonly ILoggerFactory _loggerFactory ;
7979 private readonly ILogger < GrpcChannelFactory > _logger ;
80- private readonly X509Certificate2Collection _x509Certificate2Collection ;
80+ private readonly DriverConfig _config ;
81+
82+ private X509Certificate2Collection ServerCertificates => _config . CustomServerCertificates ;
8183
8284 internal GrpcChannelFactory ( ILoggerFactory loggerFactory , DriverConfig config )
8385 {
8486 _loggerFactory = loggerFactory ;
8587 _logger = loggerFactory . CreateLogger < GrpcChannelFactory > ( ) ;
86- _x509Certificate2Collection = config . CustomServerCertificates ;
88+ _config = config ;
8789 }
8890
8991 public GrpcChannel CreateChannel ( string endpoint )
@@ -95,15 +97,18 @@ public GrpcChannel CreateChannel(string endpoint)
9597 LoggerFactory = _loggerFactory
9698 } ;
9799
98- var httpHandler = new SocketsHttpHandler ( ) ;
100+ var httpHandler = new SocketsHttpHandler
101+ {
102+ KeepAlivePingDelay = _config . KeepAlivePingDelay
103+ } ;
99104
100105 // https://github.com/grpc/grpc-dotnet/issues/2312#issuecomment-1790661801
101106 httpHandler . Properties [ "__GrpcLoadBalancingDisabled" ] = true ;
102107
103108 channelOptions . HttpHandler = httpHandler ;
104109 channelOptions . DisposeHttpClient = true ;
105110
106- if ( _x509Certificate2Collection . Count == 0 )
111+ if ( ServerCertificates . Count == 0 )
107112 {
108113 return GrpcChannel . ForAddress ( endpoint , channelOptions ) ;
109114 }
@@ -124,11 +129,11 @@ public GrpcChannel CreateChannel(string endpoint)
124129 try
125130 {
126131 chain . ChainPolicy . VerificationFlags = X509VerificationFlags . AllowUnknownCertificateAuthority ;
127- chain . ChainPolicy . ExtraStore . AddRange ( _x509Certificate2Collection ) ;
132+ chain . ChainPolicy . ExtraStore . AddRange ( ServerCertificates ) ;
128133
129- return chain . Build ( new X509Certificate2 ( certificate ) ) && chain . ChainElements . Any ( chainElement =>
130- _x509Certificate2Collection . Any ( trustedCert =>
131- chainElement . Certificate . Thumbprint == trustedCert . Thumbprint ) ) ;
134+ return chain . Build ( new X509Certificate2 ( certificate ) )
135+ && chain . ChainElements . Any ( chainElement => ServerCertificates . Any ( trustedCert =>
136+ chainElement . Certificate . Thumbprint == trustedCert . Thumbprint ) ) ;
132137 }
133138 catch ( Exception e )
134139 {
0 commit comments