Skip to content

Commit 8c65e6a

Browse files
Grpc requests go via proxy on Grpc.NET.Client >= 2.44
1 parent 523be8e commit 8c65e6a

File tree

1 file changed

+29
-26
lines changed

1 file changed

+29
-26
lines changed

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

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System.Collections.Concurrent;
22
using System.Collections.Immutable;
3+
using System.Net;
34
using System.Net.Security;
45
using System.Security.Cryptography.X509Certificates;
56
using Grpc.Core;
@@ -103,37 +104,39 @@ public GrpcChannel CreateChannel(string endpoint)
103104
return GrpcChannel.ForAddress(endpoint, channelOptions);
104105
}
105106

106-
var httpHandler = new SocketsHttpHandler();
107-
108107
var customCertificate = DotNetUtilities.FromX509Certificate(_x509Certificate);
109108

110-
httpHandler.SslOptions.RemoteCertificateValidationCallback =
111-
(_, certificate, _, sslPolicyErrors) =>
112-
{
113-
if (sslPolicyErrors == SslPolicyErrors.None)
114-
{
115-
return true;
116-
}
117-
118-
if (certificate is null)
119-
{
120-
return false;
121-
}
122-
123-
try
124-
{
125-
var cert = DotNetUtilities.FromX509Certificate(certificate);
126-
cert.Verify(customCertificate.GetPublicKey());
127-
}
128-
catch (Exception e)
109+
var httpHandler = new HttpClientHandler
110+
{
111+
ServerCertificateCustomValidationCallback =
112+
(_, certificate, _, sslPolicyErrors) =>
129113
{
130-
_logger.LogError(e, "Failed to verify remote certificate!");
114+
if (sslPolicyErrors == SslPolicyErrors.None)
115+
{
116+
return true;
117+
}
118+
119+
if (certificate is null)
120+
{
121+
return false;
122+
}
123+
124+
try
125+
{
126+
var cert = DotNetUtilities.FromX509Certificate(certificate);
127+
cert.Verify(customCertificate.GetPublicKey());
128+
}
129+
catch (Exception e)
130+
{
131+
_logger.LogError(e, "Failed to verify remote certificate!");
132+
133+
return false;
134+
}
131135

132-
return false;
136+
return true;
133137
}
134-
135-
return true;
136-
};
138+
};
139+
httpHandler.Properties["__GrpcLoadBalancingDisabled"] = true;
137140

138141
channelOptions.HttpHandler = httpHandler;
139142
channelOptions.DisposeHttpClient = true;

0 commit comments

Comments
 (0)