You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by wu...@apache.org on 2020/12/29 15:42:06 UTC

[servicecomb-java-chassis] branch master updated: [SCB-2171]avoid leak server ip when process TimeoutException

This is an automated email from the ASF dual-hosted git repository.

wujimin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-java-chassis.git


The following commit(s) were added to refs/heads/master by this push:
     new b2396eb  [SCB-2171]avoid leak server ip when process TimeoutException
b2396eb is described below

commit b2396eb06a41ad1aef85cdd28727ca7b75a5daf8
Author: liubao <bi...@qq.com>
AuthorDate: Tue Dec 29 15:57:43 2020 +0800

    [SCB-2171]avoid leak server ip when process TimeoutException
---
 .../servicecomb/demo/jaxrs/client/TestClientTimeout.java       |  2 +-
 .../servicecomb/demo/springmvc/client/SpringmvcClient.java     |  6 ++++++
 .../apache/servicecomb/transport/highway/HighwayClient.java    | 10 +++++++++-
 .../transport/rest/client/http/RestClientInvocation.java       |  5 ++++-
 4 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/demo/demo-jaxrs/jaxrs-client/src/main/java/org/apache/servicecomb/demo/jaxrs/client/TestClientTimeout.java b/demo/demo-jaxrs/jaxrs-client/src/main/java/org/apache/servicecomb/demo/jaxrs/client/TestClientTimeout.java
index 9c3ea15..73ae73d 100644
--- a/demo/demo-jaxrs/jaxrs-client/src/main/java/org/apache/servicecomb/demo/jaxrs/client/TestClientTimeout.java
+++ b/demo/demo-jaxrs/jaxrs-client/src/main/java/org/apache/servicecomb/demo/jaxrs/client/TestClientTimeout.java
@@ -75,7 +75,7 @@ public class TestClientTimeout implements CategorizedTestCase {
       // implement timeout with same error code and message for rest and highway
       TestMgr.check(408, e.getStatus().getStatusCode());
       TestMgr.check(true,
-          e.getErrorData().toString().contains("CommonExceptionData [message=Request Timeout. Details:"));
+          e.getErrorData().toString().contains("CommonExceptionData [message=Request Timeout."));
       TestMgr.check(serviceCombServerStats.getContinuousFailureCount(), failures + 1);
     }
 
diff --git a/demo/demo-springmvc/springmvc-client/src/main/java/org/apache/servicecomb/demo/springmvc/client/SpringmvcClient.java b/demo/demo-springmvc/springmvc-client/src/main/java/org/apache/servicecomb/demo/springmvc/client/SpringmvcClient.java
index e8c31a1..b3a1a79 100644
--- a/demo/demo-springmvc/springmvc-client/src/main/java/org/apache/servicecomb/demo/springmvc/client/SpringmvcClient.java
+++ b/demo/demo-springmvc/springmvc-client/src/main/java/org/apache/servicecomb/demo/springmvc/client/SpringmvcClient.java
@@ -230,6 +230,12 @@ public class SpringmvcClient {
         template.getForObject(prefix + "/controller/sayhi?name={name}",
             String.class,
             "world1"));
+
+    TestMgr.check("hi world1+world2 [world1+world2]",
+        template.getForObject(prefix + "/controller/sayhi?name={name}",
+            String.class,
+            "world1+world2"));
+
     TestMgr.check("hi hi 中国 [hi 中国]",
         template.getForObject(prefix + "/controller/sayhi?name={name}",
             String.class,
diff --git a/transports/transport-highway/src/main/java/org/apache/servicecomb/transport/highway/HighwayClient.java b/transports/transport-highway/src/main/java/org/apache/servicecomb/transport/highway/HighwayClient.java
index 4327549..630a095 100644
--- a/transports/transport-highway/src/main/java/org/apache/servicecomb/transport/highway/HighwayClient.java
+++ b/transports/transport-highway/src/main/java/org/apache/servicecomb/transport/highway/HighwayClient.java
@@ -36,6 +36,8 @@ import org.apache.servicecomb.swagger.invocation.AsyncResponse;
 import org.apache.servicecomb.swagger.invocation.Response;
 import org.apache.servicecomb.swagger.invocation.exception.CommonExceptionData;
 import org.apache.servicecomb.swagger.invocation.exception.InvocationException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import com.netflix.config.DynamicPropertyFactory;
 
@@ -43,6 +45,8 @@ import io.vertx.core.DeploymentOptions;
 import io.vertx.core.Vertx;
 
 public class HighwayClient {
+  private static final Logger LOGGER = LoggerFactory.getLogger(HighwayClient.class);
+
   private static final String SSL_KEY = "highway.consumer";
 
   private ClientPoolManager<HighwayClientConnectionPool> clientMgr;
@@ -101,8 +105,12 @@ public class HighwayClient {
           invocation.getInvocationStageTrace().finishClientFiltersResponse();
           if (ar.cause() instanceof TimeoutException) {
             // give an accurate cause for timeout exception
+            //   The timeout period of 30000ms has been exceeded while executing GET /xxx for server 1.1.1.1:8080
+            // should not copy the message to invocationException to avoid leak server ip address
+            LOGGER.info("Request timeout, Details: {}.", ar.cause().getMessage());
+
             asyncResp.consumerFail(new InvocationException(Status.REQUEST_TIMEOUT,
-                new CommonExceptionData(String.format("Request Timeout. Details: %s", ar.cause().getMessage()))));
+                new CommonExceptionData("Request Timeout.")));
             return;
           }
           asyncResp.consumerFail(ar.cause());
diff --git a/transports/transport-rest/transport-rest-client/src/main/java/org/apache/servicecomb/transport/rest/client/http/RestClientInvocation.java b/transports/transport-rest/transport-rest-client/src/main/java/org/apache/servicecomb/transport/rest/client/http/RestClientInvocation.java
index 251b27e..1cb5837 100644
--- a/transports/transport-rest/transport-rest-client/src/main/java/org/apache/servicecomb/transport/rest/client/http/RestClientInvocation.java
+++ b/transports/transport-rest/transport-rest-client/src/main/java/org/apache/servicecomb/transport/rest/client/http/RestClientInvocation.java
@@ -284,8 +284,11 @@ public class RestClientInvocation {
     try {
       if (e instanceof TimeoutException) {
         // give an accurate cause for timeout exception
+        //   The timeout period of 30000ms has been exceeded while executing GET /xxx for server 1.1.1.1:8080
+        // should not copy the message to invocationException to avoid leak server ip address
+        LOGGER.info("Request timeout, Details: {}.", e.getMessage());
         asyncResp.consumerFail(new InvocationException(Status.REQUEST_TIMEOUT,
-            new CommonExceptionData(String.format("Request Timeout. Details: %s", e.getMessage()))));
+            new CommonExceptionData("Request Timeout.")));
         return;
       }
       asyncResp.fail(invocation.getInvocationType(), e);