Skip to content

Commit cda3c9e

Browse files
authored
Avoid permanent overhead of creating TimeoutException (apache#4973)
1 parent 625441d commit cda3c9e

File tree

2 files changed

+3
-3
lines changed
  • shenyu-plugin

2 files changed

+3
-3
lines changed

shenyu-plugin/shenyu-plugin-fault-tolerance/shenyu-plugin-resilience4j/src/main/java/org/apache/shenyu/plugin/resilience4j/executor/CombinedExecutor.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public <T> Mono<T> run(final Mono<T> run, final Function<Throwable, Mono<T>> fal
4444
final Duration timeoutDuration = resilience4JConf.getTimeLimiterConfig().getTimeoutDuration();
4545
Mono<T> to = run.transformDeferred(CircuitBreakerOperator.of(circuitBreaker))
4646
.transformDeferred(RateLimiterOperator.of(rateLimiter))
47-
.timeout(timeoutDuration, Mono.error(new TimeoutException("Response took longer than timeout: " + timeoutDuration)))
47+
.timeout(timeoutDuration, Mono.error(() -> new TimeoutException("Response took longer than timeout: " + timeoutDuration)))
4848
.doOnError(TimeoutException.class, t -> circuitBreaker.onError(
4949
resilience4JConf.getTimeLimiterConfig().getTimeoutDuration().toMillis(),
5050
TimeUnit.MILLISECONDS,

shenyu-plugin/shenyu-plugin-httpclient/src/main/java/org/apache/shenyu/plugin/httpclient/AbstractHttpClientPlugin.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public final Mono<Void> execute(final ServerWebExchange exchange, final ShenyuPl
8181
LogUtils.debug(LOG, () -> String.format("The request urlPath is: %s, retryTimes is : %s, retryStrategy is : %s", uri, retryTimes, retryStrategy));
8282
final HttpHeaders httpHeaders = buildHttpHeaders(exchange);
8383
final Mono<R> response = doRequest(exchange, exchange.getRequest().getMethodValue(), uri, httpHeaders, exchange.getRequest().getBody())
84-
.timeout(duration, Mono.error(new TimeoutException("Response took longer than timeout: " + duration)))
84+
.timeout(duration, Mono.error(() -> new TimeoutException("Response took longer than timeout: " + duration)))
8585
.doOnError(e -> LOG.error(e.getMessage(), e));
8686
if (RetryEnum.CURRENT.getName().equals(retryStrategy)) {
8787
//old version of DividePlugin and SpringCloudPlugin will run on this
@@ -155,7 +155,7 @@ private Mono<R> resend(final Mono<R> response,
155155
// in order not to affect the next retry call, newUri needs to be excluded
156156
exclude.add(newUri);
157157
return doRequest(exchange, exchange.getRequest().getMethodValue(), newUri, httpHeaders, exchange.getRequest().getBody())
158-
.timeout(duration, Mono.error(new TimeoutException("Response took longer than timeout: " + duration)))
158+
.timeout(duration, Mono.error(() -> new TimeoutException("Response took longer than timeout: " + duration)))
159159
.doOnError(e -> LOG.error(e.getMessage(), e));
160160
});
161161
}

0 commit comments

Comments
 (0)