Recently I met a
context deadline exceeded error when using gRPC client to call
DialContext to a gRPC server, which was in a customer’s internal environment. After some investigation I found out the root cause, the gRPC client was behind an HTTP proxy and the proxy has no permission to access the gRPC server. It is a common trouble shooting, however I am interested in how we can force a program to use http or socks proxy, I will dive into it and compare the pros and cons among different solutions.
There exist many ways to let an application use a proxy, these ways can be classified into three types as follows, and I will talk about these methods briefly.
- Explicit environment variable to active transport feature which is builtin in the application.
- Use a hook method to hijack network calls from the application, without changing the program code.
- Use a network packet hijacking way such as the kernel netfilter module to inspect and modify network packets.