1- #region Copyright notice and license
1+ #region Copyright notice and license
22
33// Copyright 2019 The gRPC Authors
44//
@@ -114,14 +114,15 @@ internal GrpcChannel(Uri address, GrpcChannelOptions channelOptions) : base(addr
114114 LoggerFactory = channelOptions . LoggerFactory ?? channelOptions . ResolveService < ILoggerFactory > ( NullLoggerFactory . Instance ) ;
115115 OperatingSystem = channelOptions . ResolveService < IOperatingSystem > ( Internal . OperatingSystem . Instance ) ;
116116 RandomGenerator = channelOptions . ResolveService < IRandomGenerator > ( new RandomGenerator ( ) ) ;
117+ Logger = LoggerFactory . CreateLogger < GrpcChannel > ( ) ;
117118
118119#if SUPPORT_LOAD_BALANCING
119120 InitialReconnectBackoff = channelOptions . InitialReconnectBackoff ;
120121 MaxReconnectBackoff = channelOptions . MaxReconnectBackoff ;
121122
122123 var resolverFactory = GetResolverFactory ( channelOptions ) ;
123124 ResolveCredentials ( channelOptions , out _isSecure , out _callCredentials ) ;
124- ( HttpHandlerType , ConnectTimeout ) = CalculateHandlerContext ( address , _isSecure , channelOptions ) ;
125+ ( HttpHandlerType , ConnectTimeout ) = CalculateHandlerContext ( Logger , address , _isSecure , channelOptions ) ;
125126
126127 SubchannelTransportFactory = channelOptions . ResolveService < ISubchannelTransportFactory > ( new SubChannelTransportFactory ( this ) ) ;
127128
@@ -150,7 +151,7 @@ internal GrpcChannel(Uri address, GrpcChannelOptions channelOptions) : base(addr
150151 throw new ArgumentException ( $ "Address '{ address . OriginalString } ' doesn't have a host. Address should include a scheme, host, and optional port. For example, 'https://localhost:5001'.") ;
151152 }
152153 ResolveCredentials ( channelOptions , out _isSecure , out _callCredentials ) ;
153- ( HttpHandlerType , ConnectTimeout ) = CalculateHandlerContext ( address , _isSecure , channelOptions ) ;
154+ ( HttpHandlerType , ConnectTimeout ) = CalculateHandlerContext ( Logger , address , _isSecure , channelOptions ) ;
154155#endif
155156
156157 HttpInvoker = channelOptions . HttpClient ?? CreateInternalHttpInvoker ( channelOptions . HttpHandler ) ;
@@ -161,7 +162,6 @@ internal GrpcChannel(Uri address, GrpcChannelOptions channelOptions) : base(addr
161162 MaxRetryBufferPerCallSize = channelOptions . MaxRetryBufferPerCallSize ;
162163 CompressionProviders = ResolveCompressionProviders ( channelOptions . CompressionProviders ) ;
163164 MessageAcceptEncoding = GrpcProtocolHelpers . GetMessageAcceptEncoding ( CompressionProviders ) ;
164- Logger = LoggerFactory . CreateLogger < GrpcChannel > ( ) ;
165165 ThrowOperationCanceledOnCancellation = channelOptions . ThrowOperationCanceledOnCancellation ;
166166 UnsafeUseInsecureChannelCallCredentials = channelOptions . UnsafeUseInsecureChannelCallCredentials ;
167167 _createMethodInfoFunc = CreateMethodInfo ;
@@ -220,7 +220,7 @@ private static bool IsHttpOrHttpsAddress(Uri address)
220220 return address . Scheme == Uri . UriSchemeHttps || address . Scheme == Uri . UriSchemeHttp ;
221221 }
222222
223- private static HttpHandlerContext CalculateHandlerContext ( Uri address , bool isSecure , GrpcChannelOptions channelOptions )
223+ private static HttpHandlerContext CalculateHandlerContext ( ILogger logger , Uri address , bool isSecure , GrpcChannelOptions channelOptions )
224224 {
225225 if ( channelOptions . HttpHandler == null )
226226 {
@@ -267,10 +267,14 @@ private static HttpHandlerContext CalculateHandlerContext(Uri address, bool isSe
267267 // Proxy can be specified via:
268268 // - SocketsHttpHandler.Proxy. Set via app code.
269269 // - HttpClient.DefaultProxy. Set via environment variables, e.g. HTTPS_PROXY.
270- if ( IsProxied ( socketsHttpHandler , address , isSecure ) )
270+ if ( type == HttpHandlerType . SocketsHttpHandler )
271271 {
272- type = HttpHandlerType . Custom ;
273- connectTimeout = null ;
272+ if ( IsProxied ( socketsHttpHandler , address , isSecure ) )
273+ {
274+ logger . LogInformation ( "Proxy configuration is detected. How the gRPC client creates connections can cause unexpected behavior when a proxy is configured. " +
275+ "To ensure the client correctly uses a proxy, configure GrpcChannelOptions.HttpHandler to use HttpClientHandler. " +
276+ "Note that HttpClientHandler isn't compatible with load balancing." ) ;
277+ }
274278 }
275279#else
276280 type = HttpHandlerType . SocketsHttpHandler ;
0 commit comments