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

xiaoyu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-shenyu.git


The following commit(s) were added to refs/heads/master by this push:
     new 289ddeb  fix https://github.com/apache/incubator-shenyu/issues/2847 
(#2873)
289ddeb is described below

commit 289ddeb268abe3013e23012a627662f5ea800701
Author: dragon-zhang <[email protected]>
AuthorDate: Sat Feb 12 14:26:24 2022 +0800

    fix https://github.com/apache/incubator-shenyu/issues/2847 (#2873)
---
 .../src/main/http/http-test-api.http                   |  5 +++++
 .../http/controller/ShenyuClientPathController.java    | 18 +++++++++++++++++-
 .../shenyu/plugin/httpclient/WebClientPlugin.java      |  4 +++-
 3 files changed, 25 insertions(+), 2 deletions(-)

diff --git 
a/shenyu-examples/shenyu-examples-http/src/main/http/http-test-api.http 
b/shenyu-examples/shenyu-examples-http/src/main/http/http-test-api.http
index e52961b..d62ca06 100644
--- a/shenyu-examples/shenyu-examples-http/src/main/http/http-test-api.http
+++ b/shenyu-examples/shenyu-examples-http/src/main/http/http-test-api.http
@@ -18,6 +18,11 @@
 # Use gateway proxy
 # if you used IDEA, start example project. click green button.Quick access!
 
+### shengyu getway test timeout
+POST http://localhost:9195/http/shenyu/client/timeout
+Accept: application/json
+Content-Type: application/json
+
 ### shengyu getway proxy hello
 POST http://localhost:9195/http/shenyu/client/hello
 Accept: application/json
diff --git 
a/shenyu-examples/shenyu-examples-http/src/main/java/org/apache/shenyu/examples/http/controller/ShenyuClientPathController.java
 
b/shenyu-examples/shenyu-examples-http/src/main/java/org/apache/shenyu/examples/http/controller/ShenyuClientPathController.java
index 377f513..221ceed 100644
--- 
a/shenyu-examples/shenyu-examples-http/src/main/java/org/apache/shenyu/examples/http/controller/ShenyuClientPathController.java
+++ 
b/shenyu-examples/shenyu-examples-http/src/main/java/org/apache/shenyu/examples/http/controller/ShenyuClientPathController.java
@@ -40,7 +40,23 @@ public class ShenyuClientPathController {
     public String hello() {
         return "hello! " + HELLO_SUFFIX;
     }
-    
+
+    /**
+     * timeout.
+     *
+     * @return result
+     */
+    @RequestMapping("shenyu/client/timeout")
+    @ShenyuSpringMvcClient(path = "shenyu/client/timeout", desc = "shenyu 
client annotation register")
+    public String timeout() {
+        System.out.println("timeout");
+        try {
+            Thread.sleep(10000);
+        } catch (InterruptedException ignored) {
+        }
+        return "hello! " + HELLO_SUFFIX;
+    }
+
     /**
      * hello. br
      * no support gateway.
diff --git 
a/shenyu-plugin/shenyu-plugin-httpclient/src/main/java/org/apache/shenyu/plugin/httpclient/WebClientPlugin.java
 
b/shenyu-plugin/shenyu-plugin-httpclient/src/main/java/org/apache/shenyu/plugin/httpclient/WebClientPlugin.java
index 4aeb1df..7ef6058 100644
--- 
a/shenyu-plugin/shenyu-plugin-httpclient/src/main/java/org/apache/shenyu/plugin/httpclient/WebClientPlugin.java
+++ 
b/shenyu-plugin/shenyu-plugin-httpclient/src/main/java/org/apache/shenyu/plugin/httpclient/WebClientPlugin.java
@@ -18,6 +18,7 @@
 package org.apache.shenyu.plugin.httpclient;
 
 import io.netty.channel.ConnectTimeoutException;
+import io.netty.handler.timeout.ReadTimeoutException;
 import org.apache.commons.collections4.CollectionUtils;
 import org.apache.shenyu.common.constant.Constants;
 import org.apache.shenyu.common.enums.PluginEnum;
@@ -45,6 +46,7 @@ import java.time.Duration;
 import java.util.List;
 import java.util.Objects;
 import java.util.Optional;
+import java.util.concurrent.TimeoutException;
 import java.util.stream.Collectors;
 import java.util.stream.Stream;
 
@@ -118,7 +120,7 @@ public class WebClientPlugin implements ShenyuPlugin {
                 .exchange()
                 .doOnError(e -> LOG.error(e.getMessage(), e))
                 .timeout(Duration.ofMillis(timeout))
-                .retryWhen(Retry.onlyIf(x -> x.exception() instanceof 
ConnectTimeoutException)
+                .retryWhen(Retry.anyOf(TimeoutException.class, 
ConnectTimeoutException.class, ReadTimeoutException.class)
                         .retryMax(retryTimes)
                         .backoff(Backoff.exponential(Duration.ofMillis(200), 
Duration.ofSeconds(20), 2, true)))
                 .flatMap(e -> doNext(e, exchange, chain));

Reply via email to