.Net 7 - gRPC - Error - Unable to get subchannel from HttpRequestMessage

1 Answer 2289 Views
Fiddler Everywhere Windows
Philipp
Top achievements
Rank 1
Philipp asked on 23 Aug 2023, 06:01 AM

As soon as we start Fiddler Everywhere for profiling we got the following error in our application whenever a gRPC-call is executed:

Connection id "0HMT23GS5CF6U", Request id "0HMT23GS5CF6U:00000001": An unhandled exception was thrown by the application.

Error: Grpc.Core.RpcException: Status(StatusCode="Internal", Detail="Error starting gRPC call. HttpRequestException: Unable to get subchannel from HttpRequestMessage. (127.0.0.1:8866) InvalidOperationException: Unable to get subchannel from HttpRequestMessage.", DebugException="System.Net.Http.HttpRequestException: Unable to get subchannel from HttpRequestMessage. (127.0.0.1:8866)") ---> System.Net.Http.HttpRequestException: Unable to get subchannel from HttpRequestMessage. (127.0.0.1:8866) ---> System.InvalidOperationException: Unable to get subchannel from HttpRequestMessage. at Grpc.Net.Client.Balancer.Internal.BalancerHttpHandler.OnConnect(SocketsHttpConnectionContext context, CancellationToken cancellationToken) at System.Net.Http.HttpConnectionPool.ConnectToTcpHostAsync(String host, Int32 port, HttpRequestMessage initialRequest, Boolean async, CancellationToken cancellationToken)

Any idea how to fix this?

 

br

1 Answer, 1 is accepted

Sort by
0
Nick Iliev
Telerik team
answered on 23 Aug 2023, 08:39 AM

Hello Phillip,

 

The observed issue is caused by a bug in gRPC that prevents a gRPC channel to use the proxy settings. A possible solution to this would be to replace the default socket handler with the HttpHandler (which in terms, disables/removes some of the original logic and "fixes" the proxy settings usage).

For example:

// using var channel = GrpcChannel.ForAddress(URL);

// recreate the gRPC channel while using HttpClientHandler (to remove the default handler)
using var channel = GrpcChannel.ForAddress(
    URL,
    new GrpcChannelOptions
    {
        HttpHandler = new HttpClientHandler()
    });

var client = new Greeter.GreeterClient(channel);

The above describes a solution to a known bug in gRPC not respecting proxy servers (not only Fiddler but any proxy) when the default handler is being used.

 

 

Regards,
Nick Iliev
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Philipp
Top achievements
Rank 1
commented on 23 Aug 2023, 12:14 PM

@Nick Iliev

The problem is we are using the SocketsHttpHandler because there are some settings that are only available there.

Is there some special property that must be set?

Nick Iliev
Telerik team
commented on 23 Aug 2023, 01:13 PM

It seems that there is an issue with the SocketHttpHandler not following the assigned proxy configuration, which has been reported and discussed in the grpc-dotnet repository. However, a permanent solution has not yet been provided and implemented. Actually, a member of the grpc-dotnet team suggested in one of the threads that HttpClientHandler should be used when a proxy stands in the middle.

https://github.com/grpc/grpc-dotnet/issues/1832 

https://github.com/grpc/grpc-dotnet/issues/2116 

Have you considered using alternative flags in HttpClientHandler instead of the specific flags used with SocketsHttpHandler? Additionally, there are custom proxy-related properties for SocketsHttpHandler that you can try using to explicitly set the proxy. Please refer to the links below for more information. Note that neither the properties nor the grpc-dotnet library are tested or maintained by our team but by Microsoft's team.

https://learn.microsoft.com/en-us/dotnet/api/system.net.http.socketshttphandler.proxy?view=net-7.0 

https://learn.microsoft.com/en-us/dotnet/api/system.net.http.socketshttphandler.useproxy?view=net-7.0#system-net-http-socketshttphandler-useproxy 

Philipp
Top achievements
Rank 1
commented on 24 Aug 2023, 05:04 AM

Thx for the fast response!
Tags
Fiddler Everywhere Windows
Asked by
Philipp
Top achievements
Rank 1
Answers by
Nick Iliev
Telerik team
Share this question
or