Failsafe undesirably negating DataBufferException

336 views Asked by At

I am currently creating a retry mechanism for performing requests using the failsafe-lib.

The issue: the RetryPolicy that I defined includes several timeout-related exceptions, but when I use the failsafe-lib (Failsafe.with(someFallback, somePolicy).get(() -> performRequest), exceptions that I did not specify (DataBufferLimitException) to be handled are negated instead of being thrown.

Now I understand that the FailsafeExecutor(...).get() method takes a CheckedSupplier, and this (possibly) might cause in negation of unchecked exceptions (please correct me if I'm wrong, this is just an assumption). However, I am still curious if I have done something wrong and if there is something that I can do to resolve this issue.

Below I have a simplified version of my code:

public Response performRequest() {

        RetryPolicy<Object> retryPolicy = RetryPolicy.builder()
                .withDelay(Duration.ofMillis(60_000L))
                .handle(exceptionA, exceptionB, ...)
                .withMaxRetries(3)
                .onSuccess(o -> log.info("someRandomMessage"))
                .onFailure(o -> log.warn("someRandomWarnMessage"))
                .onRetriesExceeded(o -> log.error("someRandomErrorMessage"))
                .build();

        Fallback<Object> fallback = Fallback.of(event -> {
                Throwable rootException = ExceptionUtils.getRootCause(event.getLastException());
                if (rootException instanceof TimeoutException || rootException instanceof ConnectException) {
                    throw new someRandomException(rootException.getMessage());
                }
            }
        );

        Response response Failsafe.with(fallback, retryPolicy).get(() -> someRequest);
        return response;

The scenario that is performed with this code:

We perform a request and (during testing) we expect to see an unchecked exception. However, this exception is 'swallowed' by functionality of the failsafe-lib, while I in fact want to see back this exception. I know this is more on my end, but I'm not sure how to fix this issue. Any tips, alternatives or corrections are much appreciated.

1

There are 1 answers

0
Dominique M On

Found my own mistake: if the if-statement was not triggered, no exception would be thrown and null would be returned. This resulted in an empty response, etc.