Defer instantiation of TimeoutExcpetions.

By deferring instantiation of TimeoutExcpetions on each request, this prevents an agent, like Dynatrace, from thinking all requests are throwing TimeoutExceptions.

Fixes gh-2600
Fixes gh-3344
This commit is contained in:
John Gray
2024-04-09 11:44:26 -04:00
committed by spencergibb
parent f444ad5cf2
commit eb1de2a37c

View File

@@ -191,7 +191,7 @@ public class NettyRoutingFilter implements GlobalFilter, Ordered {
if (responseTimeout != null) {
responseFlux = responseFlux
.timeout(responseTimeout,
Mono.error(new TimeoutException("Response took longer than timeout: " + responseTimeout)))
Mono.defer(() -> Mono.error(new TimeoutException("Response took longer than timeout: " + responseTimeout))))
.onErrorMap(TimeoutException.class,
th -> new ResponseStatusException(HttpStatus.GATEWAY_TIMEOUT, th.getMessage(), th));
}