Set no_proxy=localhost when an http_proxy is detected, instead of deleting the http_proxy value.
Also change the environment for the client and the server in this case, instead of only changing the server's environment.
RELNOTES: None.
@@ -1354,9 +1354,23 @@ static void ComputeBaseDirectories(const WorkspaceLayout *workspace_layout,
static map<string, EnvVarValue> PrepareEnvironmentForJvm() {
map<string, EnvVarValue> result;
- if (!blaze::GetEnv("http_proxy").empty()) {
- BAZEL_LOG(WARNING) << "ignoring http_proxy in environment.";
- result["http_proxy"] = EnvVarValue(EnvVarAction::UNSET, "");
+ // We need to disable HTTP proxies for local (gRPC-based) communication
+ // between the client and server. gRPC currently only checks http_proxy, but
+ // HTTP_PROXY could also be used to specify a proxy, so we check for both.
+ if (!blaze::GetEnv("http_proxy").empty() ||
+ !blaze::GetEnv("HTTP_PROXY").empty()) {
+ BAZEL_LOG(WARNING)
+ << "detected http_proxy set in env, setting no_proxy for localhost.";
+
+ // Disable HTTP proxies for localhost and any localhost-like address,
+ // in case we (or gRPC, etc.) ever use one of these addresses.
+ std::string localhost_addresses = "localhost,127.0.0.1,0:0:0:0:0:0:0:1,::1";
+ result["no_proxy"] = EnvVarValue(EnvVarAction::SET, localhost_addresses);
+ result["NO_PROXY"] = EnvVarValue(EnvVarAction::SET, localhost_addresses);
+
+ // Set no_proxy for the client, as well.
+ blaze::SetEnv("no_proxy", localhost_addresses);
+ blaze::SetEnv("NO_PROXY", localhost_addresses);
}
if (!blaze::GetEnv("LD_ASSUME_KERNEL").empty()) {
