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

Proxy cannot be used when deployed to the Linux #320

Closed
lileixer opened this issue Oct 20, 2021 · 23 comments
Closed

Proxy cannot be used when deployed to the Linux #320

lileixer opened this issue Oct 20, 2021 · 23 comments
Assignees
Labels
bug Something isn't working

Comments

@lileixer
Copy link

Hi
I configured the proxy and it was available locally, but when deployed on a Linux server the program threw an exception
The error message is:(StatusCode="Unavailable", Detail="failed to connect to all addresses", DebugException="Grpc.Core.Internal.CoreErrorDetailException: {"created":"@1634714686.033195058","description":"Failed to pick subchannel","file":"/var/local/git/grpc/src/core/ext/filters/client_channel/client_channel.cc","file_line":5397,"referenced_errors":[{"created":"@1634714686.033187157","description":"failed to connect to all addresses","file":"/var/local/git/grpc/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc","file_line":398,"grpc_status":14}]}"). Grpc.Core.RpcException: Status(StatusCode="Unavailable", Detail="failed to connect to all addresses", DebugException="Grpc.Core.Internal.CoreErrorDetailException: {"created":"@1634714686.033195058","description":"Failed to pick subchannel","file":"/var/local/git/grpc/src/core/ext/filters/client_channel/client_channel.cc","file_line":5397,"referenced_errors":[{"created":"@1634714686.033187157","description":"failed to connect to all addresses","file":"/var/local/git/grpc/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc","file_line":398,"grpc_status":14}]}")

@lileixer lileixer added the bug Something isn't working label Oct 20, 2021
@AnashOommen
Copy link
Member

AnashOommen commented Oct 25, 2021

@lileixer I use what the grpc library provides, so let me ask someone from the team to chime in. What proxy string are you using? Could you share it?

@AnashOommen AnashOommen self-assigned this Oct 25, 2021
@lileixer
Copy link
Author

Thanks a lot. Of course I would.But this is a private proxy, I hope I can send it to you separately. My email is leilichn005@gmail.com, please send me an email and I will reply to you.

@jtattermusch
Copy link

Some general advice that might help:

  • You might get some extra insights by setting GRPC_VERBOSITY=debug env variable and then inspecting the logs, as described here:
    https://github.com/grpc/grpc/blob/master/TROUBLESHOOTING.md#grpc_verbosity. You can also use GRPC_TRACE=tcp to see the actual bytes being sent by gRPC (it might help to debug the problem).
  • are you sure that the proxy you are using supports HTTP/2? This is a requirements for being able to proxy grpc traffic (as gRPC is based on HTTP/2 protocol).
  • are you using secure or insecure connection? Setting up insecure proxy is easier, so that's where I would start with experiments.
  • seeing at least the format of the URL you are using for http_proxy would help. Can you share what software is the proxy?

relevant proxy configuration code:
https://github.com/grpc/grpc/blob/c8db1091b8c02f5cf7ac1cb2f30363141ce28023/src/core/ext/filters/client_channel/http_proxy.cc#L71

@lileixer
Copy link
Author

@jtattermusch
I use the proxy software is clash, https://github.com/Dreamacro/clash/releases/tag/premium
I tried to configure the debug environment variable, but I could not find the reason from the log.
I can share the proxy string with you separately. If necessary, you can send me an email. The email address is leilichn005@gmail.com

@jtattermusch
Copy link

From the documentation it's not obvious to me whether the proxy you use supports HTTP 2.0
https://github.com/Dreamacro/clash/blob/master/README.md

Can you share the obfuscated proxy URL here (e.g. replace IP address with random number or replace hostname with random characters, just keep the structure of the URL)?

@lileixer
Copy link
Author

@jtattermusch
Proxy: http://xxx.xxx.xxx.xxx:8080
It's definitely supported, and the GoogleAds sample works fine on a Windows development environment

@jtattermusch
Copy link

@jtattermusch Proxy: http://xxx.xxx.xxx.xxx:8080 It's definitely supported, and the GoogleAds sample works fine on a Windows development environment

Ok, so I'm I understanding correctly that the exact same setup works fine on Windows and it doesn't work on Linux (Linux vs Windows being the only difference here?)

@lileixer
Copy link
Author

@jtattermusch
That's true.

@jtattermusch
Copy link

@jtattermusch That's true.

Any interesting differences in the logs when GRPC_VERBOSITY=debug and GRPC_TRACE=tcp are set? On linux there should be some logs that suggest why connecting has failed (bad security handshake? ip unreachable from linux?) or some difference in the bytes that gets sent once the proxy is established.

@lileixer
Copy link
Author

@jtattermusch
I'll show you the log after I reproduce the problem

@lileixer
Copy link
Author

@jtattermusch

微信截图_20211026185821

After doing the configuration, the log is as follows
windows.txt
linux.txt

@jtattermusch
Copy link

The lack of useful linux logs seems surprising. Can you try with GRPC_TRACE=handshaker and also GRPC_DNS_RESOLVER=native (since the windows log mentions that it's using native DNS resolver, which isn't the default btw).

Which Grpc.Core version are you using?

@jtattermusch
Copy link

Ok, I think I know what's wrong. Don't use Environment.SetEnvironmentVariable() on linux.
It doesn't actually set the env values the internal native library sees (see grpc/grpc#14963 for details).
To set env variables on linux, set them on command line or in a shell script.

this might be the reason why no useful logs are printed on linux and why http_proxy on linux appears to not work (the real problem is that the C-core library doesn't see those env variables being set).

Also see grpc/grpc#19706

@lileixer
Copy link
Author

Thanks, let me try

@lileixer
Copy link
Author

@jtattermusch
Thank you very much!
When I run "export http_proxy=http://myproxy.com:7890" command on Linux to set the environment variables, the program runs smoothly and the problem is solved.

@jtattermusch
Copy link

Let's close this issue then?

@lileixer
Copy link
Author

OK

@lileixer lileixer reopened this Oct 28, 2021
@lileixer
Copy link
Author

@jtattermusch

Today I encountered a new problem. There are two places in my project that need to use a proxy, one is GoogleSDK and the other is for other platforms. The two places need to use different proxy addresses, and the environment variable configuration cannot be isolated. How can I Does the operation make it read the project configuration? (Project deployment to Linux)

@jtattermusch
Copy link

If you have access to the creation of gRPC channels and you can add extra configuration,
you can set the proxy on per-channel basis via a channel argument (or "ChannelOption" in gRPC C#).

During creating of the channel, you can pass new ChannelOption("grpc.http_proxy","YOUR_PROXY_URL")
https://github.com/grpc/grpc/blob/09658682c93805d5114a0d638388349c4276f9a3/include/grpc/impl/codegen/grpc_types.h#L418

If you don't have access to the channel creation (not sure if the ads client library provides that), you're out of luck, since the only other option is setting the enviroment variable.

@lileixer
Copy link
Author

image
image
Looking at the source code, the CreateChannel packaged by the SDK still implements the proxy by setting environment variables. Does this mean that the existing SDK can't do what I want to do

@lileixer
Copy link
Author

I'm trying to pull a branch and change the implementation

@AnashOommen
Copy link
Member

AnashOommen commented Oct 28, 2021 via email

@lileixer
Copy link
Author

Looking forward to your update

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants