-
Notifications
You must be signed in to change notification settings - Fork 38.7k
Description
Hi Spring-Team,
After upgrading to Spring Boot 3.4.0, we have encountered an issue with RestTemplate where random CancellationExceptions are thrown instead of the expected ResourceAccessException during timeout scenarios.
Observations:
This behavior is inconsistent; sometimes a CancellationException is thrown, and other times a ResourceAccessException is thrown.
This issue did not occur in previous versions of Spring Boot.
Reproduction:
We have created a test case to demonstrate the issue: https://github.com/SimonPNorra/timeout-execption-case
Steps to Reproduce:
Run the test case included in the project and observe the exceptions thrown. You will notice either a CancellationException or a ResourceAccessException occurring randomly.
Expected Behavior:
Consistent behavior with ResourceAccessException thrown during timeout scenarios.
Actual Behavior:
Random exceptions are thrown: either CancellationException or ResourceAccessException.
Please let us know if further information is required.
Thank you.
Regards
Activity
wilkinsona commentedon Nov 26, 2024
Thanks for the sample.
Unfortunately, on my machine, it doesn't reproduce the behavior that you've described. I've tried with both Java 21 and Java 23 and the exception was always a
ResourceAccessException
. I'm on macOS 14.7.1.Can you please provide some more information about the OS you're running on and the version and distribution of Java that you're using? Also, please share the full stack trace of both the
CancellationException
and theResourceAccessException
that you're seeing.SimonPNorra commentedon Nov 27, 2024
Hey @wilkinsona
Thank you for looking into this issue. Here is the information about my local machine, which I used to run the example:
Machine Details:
Device: MacBook Pro
Processor: Apple M1 Pro
Operating System: macOS 15.1.1 (24B91)
JDK: azul-21.0.2 (aarch64)
Stack Traces from the Example:
(Below are both stack traces as observed from running the test case.)
In addition, this issue first appeared in our application running as a GCP CloudRun service. The service operates using the following base image:
FROM gcr.io/distroless/java21-debian12
Let me know if you need more details about the environment!
wilkinsona commentedon Nov 27, 2024
Thanks for the additional details and stack traces. The change in behavior that you've seen upon upgrading to Spring Boot 3.4 is due to this change in Spring Framework. We'll transfer this issue to the Framework team so that they can continue the investigation.
SimonPNorra commentedon Nov 27, 2024
Hi there,
I’ve updated my example project to include additional test scenarios:
gcr.io/distroless/java21-debian12
, replicating the execution environment where this issue was originally observedI hope these additions help with your investigation.
Thank you for your support!
aldex32 commentedon Jan 31, 2025
I am having the same issue as @SimonPNorra
jaceko commentedon Mar 20, 2025
I'm having the same issue on Linux (JDK 21, Spring boot 3.4.3)
Fix throws only ResourceAccessException on timeout spring-projects#33973
Fix throws only ResourceAccessException on timeout spring-projects#33973
Fix throws only ResourceAccessException on timeout
11 remaining items
rstoyanchev commentedon Aug 1, 2025
In the TimeoutHandler we call
CompletableFuture#cancel
and the Javadoc for that says:However, in some cases it is wrapped in
ExecutionException
and others it is not. Below is a stracktrace from when it is wrapped, and the cause is identical to when it is not wrapped as shown in comments above.Currently we only handle the wrapped case, but should also handle it not wrapped.
CancellationExceptions are thrown instead of the expected ResourceAcc…
rstoyanchev commentedon Aug 8, 2025
Superseded by #34721.
Handle CancellationException in JdkClientHttpRequest