Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue after update to 2.52.0 #2075

Closed
plombaer opened this issue Mar 16, 2023 · 12 comments
Closed

Issue after update to 2.52.0 #2075

plombaer opened this issue Mar 16, 2023 · 12 comments
Labels
question Further information is requested

Comments

@plombaer
Copy link

plombaer commented Mar 16, 2023

Dear
Since the upgrade I'm getting the following error :
System.InvalidOperationException: 'Channel is configured with an HTTP transport doesn't support client-side load balancing or connectivity state tracking. The underlying HTTP transport must be a SocketsHttpHandler with no SocketsHttpHandler.ConnectCallback configured. The HTTP transport must be configured on the channel using GrpcChannelOptions.HttpHandler.'

My service is hosted in IIS using gRPC.Web with client load balancing.
All was working fine before the update.
Here is my client code:

            var credentials = CallCredentials.FromInterceptor((c, m) =>
            {
                m.Add("Authorization", "Bearer " + ...;
                return Task.CompletedTask;
            });
            var clientHandler = new SocketsHttpHandler();
            clientHandler.UseProxy = false;
            clientHandler.EnableMultipleHttp2Connections = false;
            clientHandler.SslOptions = new SslClientAuthenticationOptions
            {
                RemoteCertificateValidationCallback = ValidateServerCertificate,
            };
            var channel = GrpcChannel.ForAddress("dns:///...", new GrpcChannelOptions
            {
                HttpHandler = new GrpcWebHandler(new SubdirectoryHandler(clientHandler, "/...")),
                Credentials = ChannelCredentials.Create(ChannelCredentials.SecureSsl, credentials),

                //UnsafeUseInsecureChannelCallCredentials = true,
                ServiceConfig = new ServiceConfig
                {
                    LoadBalancingConfigs = { new RoundRobinConfig() }
                }
            });
@plombaer plombaer added the question Further information is requested label Mar 16, 2023
@JamesNK
Copy link
Member

JamesNK commented Mar 16, 2023

That error should only happen if you're configuring SocketsHttpHandler.ConnectCallback, which you aren't doing in the sample in your issue.

Could you create a reproduction of the problem and put it in a GitHub repo? I'll take a look.

@plombaer
Copy link
Author

TestGrpcWeb.zip
Here is my test project

@JamesNK
Copy link
Member

JamesNK commented Mar 19, 2023

I didn't get that error. It worked for me.

I tested with Kestrel, so I needed to modify the sample slightly not to use TLS, modify the path, and use a static load balancer instead of DNS, but that shouldn't impact the error.

image

@plombaer
Copy link
Author

If I give a dummy uri and comment ServiceConfig it doesn't crash anymore on GrpcChannel.ForAddress
I suppose the issue rises when there is a DNS.

@JamesNK
Copy link
Member

JamesNK commented Mar 20, 2023

If I use DNS then I get a different error, but the error is because I don't have a DNS server at that address:

image

Just so you know, this error would happen after the point where your error occurred.

The code you've provided shouldn't cause this error, and I can't reproduce it.

@JasonSingleton
Copy link

I believe this issue is been caused by 5a0b1ee

Even though the handler is configured to not use a proxy one is determined by var proxy = socketsHttpHandler.Proxy ?? HttpClient.DefaultProxy; Its ignoring the UseProxy property on the handler

This never returns false basically on my system when a load balancer is configured, I assume the same is happening for @plombaer so exiting it then sets the handler type to be Custom and then causing the error later in the code.

@JamesNK
Copy link
Member

JamesNK commented Mar 24, 2023

Yes, that would easily explain it. I think there are two options:

  1. Improve the error message to say that load balancing isn't supported because there is a proxy.
  2. Log a warning instead of preventing load balancing from working when there is a proxy.

@JasonSingleton
Copy link

JasonSingleton commented Mar 24, 2023

Well adding below to IsProxied line 299 in GrpcChannel.cs fixes the immediate issue.

if (!socketsHttpHandler.UseProxy) {
return false;
}

On the proxy side are you saying it can't work if a proxy is present? But there is no reason it can't work (obviously will have a performance impact) but it will still load balance on the target group of servers?

@eduardobr
Copy link

On the proxy side are you saying it can't work if a proxy is present? But there is no reason it can't work (obviously will have a performance impact) but it will still load balance on the target group of servers?

I would say the same, I have an address that resolves to 2 different records and load balances correctly even being behind a proxy. Works in 2.51 and shows me the error reported here when I switch to 2.52.

@topsterde
Copy link

I also get the same error. Here is a very simple example. When will there be a solution to the error?
GrpcInvalidOperationExceptionConstructor.zip

@plombaer
Copy link
Author

plombaer commented Apr 8, 2023

Hi
Just to be clear I had deactivated the proxy usage:
var clientHandler = new SocketsHttpHandler();
clientHandler.UseProxy = false;

@JamesNK
Copy link
Member

JamesNK commented Apr 8, 2023

2.53.0 will revert back to 2.51.0 behavior. Now a log message is written if a proxy is detected.

Use 2.51.0 until it's available.

@JamesNK JamesNK closed this as completed Aug 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

5 participants