question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Fallback Method in @Fallback not being called when combined with @Retry

See original GitHub issue

Environment 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:closed
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
spericascommented, Feb 8, 2021

Trying to get https://github.com/oracle/helidon/pull/2748 into 2.2.1 to be released this week. Should fix this issue.

0reactions
spericascommented, Feb 9, 2021

PR #2748 merged.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found