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/shenyu.git


The following commit(s) were added to refs/heads/master by this push:
     new cda3c9e8b Avoid permanent overhead of creating TimeoutException (#4973)
cda3c9e8b is described below

commit cda3c9e8ba8aa99b96cf0ed8ade4ba9cf656137f
Author: 吴伟杰 <[email protected]>
AuthorDate: Wed Aug 9 17:39:42 2023 +0800

    Avoid permanent overhead of creating TimeoutException (#4973)
---
 .../apache/shenyu/plugin/resilience4j/executor/CombinedExecutor.java  | 2 +-
 .../org/apache/shenyu/plugin/httpclient/AbstractHttpClientPlugin.java | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git 
a/shenyu-plugin/shenyu-plugin-fault-tolerance/shenyu-plugin-resilience4j/src/main/java/org/apache/shenyu/plugin/resilience4j/executor/CombinedExecutor.java
 
b/shenyu-plugin/shenyu-plugin-fault-tolerance/shenyu-plugin-resilience4j/src/main/java/org/apache/shenyu/plugin/resilience4j/executor/CombinedExecutor.java
index d266b5bf2..4dd7dd616 100644
--- 
a/shenyu-plugin/shenyu-plugin-fault-tolerance/shenyu-plugin-resilience4j/src/main/java/org/apache/shenyu/plugin/resilience4j/executor/CombinedExecutor.java
+++ 
b/shenyu-plugin/shenyu-plugin-fault-tolerance/shenyu-plugin-resilience4j/src/main/java/org/apache/shenyu/plugin/resilience4j/executor/CombinedExecutor.java
@@ -44,7 +44,7 @@ public class CombinedExecutor implements Executor {
         final Duration timeoutDuration = 
resilience4JConf.getTimeLimiterConfig().getTimeoutDuration();
         Mono<T> to = 
run.transformDeferred(CircuitBreakerOperator.of(circuitBreaker))
                 .transformDeferred(RateLimiterOperator.of(rateLimiter))
-                .timeout(timeoutDuration, Mono.error(new 
TimeoutException("Response took longer than timeout: " + timeoutDuration)))
+                .timeout(timeoutDuration, Mono.error(() -> new 
TimeoutException("Response took longer than timeout: " + timeoutDuration)))
                 .doOnError(TimeoutException.class, t -> circuitBreaker.onError(
                         
resilience4JConf.getTimeLimiterConfig().getTimeoutDuration().toMillis(),
                         TimeUnit.MILLISECONDS,
diff --git 
a/shenyu-plugin/shenyu-plugin-httpclient/src/main/java/org/apache/shenyu/plugin/httpclient/AbstractHttpClientPlugin.java
 
b/shenyu-plugin/shenyu-plugin-httpclient/src/main/java/org/apache/shenyu/plugin/httpclient/AbstractHttpClientPlugin.java
index 12b7291f5..096d710ca 100644
--- 
a/shenyu-plugin/shenyu-plugin-httpclient/src/main/java/org/apache/shenyu/plugin/httpclient/AbstractHttpClientPlugin.java
+++ 
b/shenyu-plugin/shenyu-plugin-httpclient/src/main/java/org/apache/shenyu/plugin/httpclient/AbstractHttpClientPlugin.java
@@ -81,7 +81,7 @@ public abstract class AbstractHttpClientPlugin<R> implements 
ShenyuPlugin {
         LogUtils.debug(LOG, () -> String.format("The request urlPath is: %s, 
retryTimes is : %s, retryStrategy is : %s", uri, retryTimes, retryStrategy));
         final HttpHeaders httpHeaders = buildHttpHeaders(exchange);
         final Mono<R> response = doRequest(exchange, 
exchange.getRequest().getMethodValue(), uri, httpHeaders, 
exchange.getRequest().getBody())
-                .timeout(duration, Mono.error(new TimeoutException("Response 
took longer than timeout: " + duration)))
+                .timeout(duration, Mono.error(() -> new 
TimeoutException("Response took longer than timeout: " + duration)))
                 .doOnError(e -> LOG.error(e.getMessage(), e));
         if (RetryEnum.CURRENT.getName().equals(retryStrategy)) {
             //old version of DividePlugin and SpringCloudPlugin will run on 
this
@@ -155,7 +155,7 @@ public abstract class AbstractHttpClientPlugin<R> 
implements ShenyuPlugin {
             // in order not to affect the next retry call, newUri needs to be 
excluded
             exclude.add(newUri);
             return doRequest(exchange, exchange.getRequest().getMethodValue(), 
newUri, httpHeaders, exchange.getRequest().getBody())
-                    .timeout(duration, Mono.error(new 
TimeoutException("Response took longer than timeout: " + duration)))
+                    .timeout(duration, Mono.error(() -> new 
TimeoutException("Response took longer than timeout: " + duration)))
                     .doOnError(e -> LOG.error(e.getMessage(), e));
         });
     }

Reply via email to