@@ -75,17 +75,17 @@ public interface IChannelFactory<out T> where T : ChannelBase, IDisposable
7575
7676internal class GrpcChannelFactory : IChannelFactory < GrpcChannel >
7777{
78- private const int KeepAlivePingDelaySeconds = 10 ;
79-
8078 private readonly ILoggerFactory _loggerFactory ;
8179 private readonly ILogger < GrpcChannelFactory > _logger ;
82- private readonly X509Certificate2Collection _x509Certificate2Collection ;
80+ private readonly DriverConfig _config ;
81+
82+ private X509Certificate2Collection ServerCertificates => _config . CustomServerCertificates ;
8383
8484 internal GrpcChannelFactory ( ILoggerFactory loggerFactory , DriverConfig config )
8585 {
8686 _loggerFactory = loggerFactory ;
8787 _logger = loggerFactory . CreateLogger < GrpcChannelFactory > ( ) ;
88- _x509Certificate2Collection = config . CustomServerCertificates ;
88+ _config = config ;
8989 }
9090
9191 public GrpcChannel CreateChannel ( string endpoint )
@@ -94,21 +94,24 @@ public GrpcChannel CreateChannel(string endpoint)
9494
9595 var channelOptions = new GrpcChannelOptions
9696 {
97- LoggerFactory = _loggerFactory
97+ LoggerFactory = _loggerFactory ,
98+ DisposeHttpClient = true
9899 } ;
99100
100101 var httpHandler = new SocketsHttpHandler
101102 {
102- KeepAlivePingDelay = TimeSpan . FromSeconds ( KeepAlivePingDelaySeconds )
103+ // https://github.com/grpc/proposal/blob/master/A8-client-side-keepalive.md
104+ KeepAlivePingDelay = _config . KeepAlivePingDelay ,
105+ KeepAlivePingTimeout = _config . KeepAlivePingTimeout ,
106+ KeepAlivePingPolicy = HttpKeepAlivePingPolicy . Always
103107 } ;
104108
105109 // https://github.com/grpc/grpc-dotnet/issues/2312#issuecomment-1790661801
106110 httpHandler . Properties [ "__GrpcLoadBalancingDisabled" ] = true ;
107111
108112 channelOptions . HttpHandler = httpHandler ;
109- channelOptions . DisposeHttpClient = true ;
110113
111- if ( _x509Certificate2Collection . Count == 0 )
114+ if ( ServerCertificates . Count == 0 )
112115 {
113116 return GrpcChannel . ForAddress ( endpoint , channelOptions ) ;
114117 }
@@ -129,11 +132,11 @@ public GrpcChannel CreateChannel(string endpoint)
129132 try
130133 {
131134 chain . ChainPolicy . VerificationFlags = X509VerificationFlags . AllowUnknownCertificateAuthority ;
132- chain . ChainPolicy . ExtraStore . AddRange ( _x509Certificate2Collection ) ;
135+ chain . ChainPolicy . ExtraStore . AddRange ( ServerCertificates ) ;
133136
134- return chain . Build ( new X509Certificate2 ( certificate ) ) && chain . ChainElements . Any ( chainElement =>
135- _x509Certificate2Collection . Any ( trustedCert =>
136- chainElement . Certificate . Thumbprint == trustedCert . Thumbprint ) ) ;
137+ return chain . Build ( new X509Certificate2 ( certificate ) ) &&
138+ chain . ChainElements . Any ( chainElement => ServerCertificates . Any ( trustedCert =>
139+ chainElement . Certificate . Thumbprint == trustedCert . Thumbprint ) ) ;
137140 }
138141 catch ( Exception e )
139142 {
0 commit comments