乱设置系统参数导致RPC调用异常

设置系统参数如下:

System.setProperty("proxyHost", "localhost");
System.setProperty("proxyPort", "1080");

PRC调用异常如下:
Caused by: java.net.ConnectException: Failed to connect to localhost/0:0:0:0:0:0:0:1:1080
    at okhttp3.internal.connection.RealConnection.connectSocket(RealConnection.java:265)
    at okhttp3.internal.connection.RealConnection.connectTunnel(RealConnection.java:235)
    at okhttp3.internal.connection.RealConnection.connect(RealConnection.java:177)
    at okhttp3.internal.connection.ExchangeFinder.findConnection(ExchangeFinder.java:224)
    at okhttp3.internal.connection.ExchangeFinder.findHealthyConnection(ExchangeFinder.java:108)
    at okhttp3.internal.connection.ExchangeFinder.find(ExchangeFinder.java:88)
    at okhttp3.internal.connection.Transmitter.newExchange(Transmitter.java:169)
    at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:41)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:117)
    at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:94)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:117) 
        at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142)
    at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:88)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142)
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:117)
    at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:229)
    at okhttp3.RealCall.execute(RealCall.java:81)
    at com.aliyun.tea.Tea.doAction(Tea.java:67)
原因分析:

根据异常信息提示:是因为配置了系统参数 导致在进行RPC 调用时异常,根据异常堆栈信息找到
sun.net.spi.DefaultProxySelector.List select(URI var1) 发现如下代码:

if (var3 != null && var3.length() != 0) {
      if (var11 != null) {
          var5 = NetProperties.get(var11.property);
          synchronized (var11) {
              if (var5 == null) {
                  if (var11.defaultVal != null) {
                      var5 = var11.defaultVal;
                  } else {
                      var11.hostsSource = null;
                      var11.pattern = null;
                  }
              } else if (var5.length() != 0) {
                  var5 = var5 + "|localhost|127.*|[::1]|0.0.0.0|[::0]"; 
              }
              if (var5 != null && !var5.equals(var11.hostsSource)) {
                  var11.pattern = DefaultProxySelector.toPattern(var5);
                  var11.hostsSource = var5;
              }
              if (DefaultProxySelector.shouldNotUseProxyFor(var11.pattern, var8)) {
                  return Proxy.NO_PROXY;
              }
          }
      }
  }

根据以上代码发现


image.png
image.png

最终走的是本地的代理,所以会请求不通

解决以上问题方法:

删掉以上配置即可

你可能感兴趣的:(乱设置系统参数导致RPC调用异常)