Fallback Method in @Fallback not being called when combined with @Retry
See original GitHub issueEnvironment Details
- Helidon Version: 2.2.0
- Helidon MP
- JDK version: JDK 11.0.7
- OS: Windows 10
- Docker version (if applicable):
Problem Description
The fallback method defined in @Fallback is not getting called after reaching max retries when the target method is also annotated with @Retry. When the target method is only annotated with @Fallback, the fallback method gets called when the execution of the target method failed.
Expected behavior: The fallback method get called after the max number of retries has been reached.
Steps to reproduce
With Resource as:
`
private final BusinessService businessService;
@Inject
public GreetResource(BusinessService businessService) {
this.businessService = businessService;
}
@POST
@Path("/process")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response processReversal(JsonObject jsonObject) {
String requestId = jsonObject.getString("requestId");
String result = businessService.callUnreliableApi(requestId);
return Response.status(Response.Status.NO_CONTENT).build();
}`
And Business service as: `@ApplicationScoped public class BusinessService {
@Fallback(fallbackMethod = "testFallback", applyOn = RuntimeException.class)
@Retry(maxRetries = 3, retryOn = RuntimeException.class )
public String callUnreliableApi(String requestId) {
HttpURLConnection conn = null;
int responseCode = -1;
try {
URL obj = new URL("http://localhost:8080/api");
conn = (HttpURLConnection) obj.openConnection();
conn.setRequestMethod("GET");
responseCode = conn.getResponseCode();
String responseMsg = conn.getResponseMessage();
}
catch (IOException e) {
throw new RuntimeException("IOException ocurred");
}finally {
if (conn != null) {
conn.disconnect();
}
}
if (responseCode != 200 ) {
throw new RuntimeException("Unsuccessful call");
}
return "API called successfully!";
}
public String testFallback(String requestId) {
return "API call failed!";
}
}`
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Fallback method not being executed · Issue #1408 - GitHub
I have an @Async method where I'm trying to add @Retry but the fallback method is never being executed when an exception occurs....
Read more >Recover (fallback method) is not getting invoked when used ...
Recover method is not getting called at all, I have tried with all possible type of method parameters and changing the return type...
Read more >Failover and Circuit Breaker with Resilience4j | by Rob Golder
Here we see there are two overloaded fallback methods. In fact any number can be provided, with the last argument, the exception type,...
Read more >Circuit Breaker And Retry with Spring Cloud Resiliance4j
This is because the circuit breaker fallback method was called directly and the retry was not triggered.
Read more >Retry with Spring Boot and Resilience4j - Reflectoring
A deep dive into the Spring Boot Resilience4j Retry module, this article ... The fallback method should be defined in the same class...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Trying to get https://github.com/oracle/helidon/pull/2748 into 2.2.1 to be released this week. Should fix this issue.
PR #2748 merged.