spring-retry icon indicating copy to clipboard operation
spring-retry copied to clipboard

The FixedBackOffPolicy method setBackOffPeriod(long) if set to 0 or less than .The backOffPeriod value not is 1000ms.

Open yahyaoo opened this issue 5 years ago • 2 comments

Class: org.springframework.retry.backoff.FixedBackOffPolicy Method: public void setBackOffPeriod(long backOffPeriod)

source code:


	private static final long DEFAULT_BACK_OFF_PERIOD = 1000L;

	private volatile long backOffPeriod = DEFAULT_BACK_OFF_PERIOD;

	....//omit

	public void setBackOffPeriod(long backOffPeriod) {
		this.backOffPeriod = (backOffPeriod > 0 ? backOffPeriod : 1); //here
	}

	....//omit
	

suggest code:


	private static final long DEFAULT_BACK_OFF_PERIOD = 1000L;

	private volatile long backOffPeriod = DEFAULT_BACK_OFF_PERIOD;

	....//omit

	public void setBackOffPeriod(long backOffPeriod) {
		this.backOffPeriod = (backOffPeriod > 0 ? backOffPeriod : DEFAULT_BACK_OFF_PERIOD); //here
	}

	....//omit
	

yahyaoo avatar Nov 06 '20 03:11 yahyaoo

test code:

    @Test
    public void fixedBackOffPolicyTest() {
        FixedBackOffPolicy backOffPolicy = new FixedBackOffPolicy();
        backOffPolicy.setBackOffPeriod(0);
        RetryTemplate retryTemplate = RetryTemplate.builder()
                .customBackoff(backOffPolicy)
                .build();

        Object execute = null;
        try {
            execute = retryTemplate.execute(new RetryCallback<Object, Throwable>() {
                @Override
                public Object doWithRetry(RetryContext context) throws Throwable {
                    log.info("RetryCallback:" + context.getRetryCount());
                    throw new IllegalArgumentException();
                    //return "RetryCallback";
                }
            }, new RecoveryCallback<Object>() {
                @Override
                public Object recover(RetryContext context) throws Exception {
                    log.info("RecoveryCallback:" + context.getRetryCount());
                    return "RecoveryCallback";
                }
            });
        } catch (Throwable throwable) {
            log.error(throwable.getMessage(), throwable);
        }

        log.info("result:" + execute);
    }

yahyaoo avatar Nov 06 '20 03:11 yahyaoo

This is indeed a bug, but I'm not sure that we can make a breaking change in behavior in the current point version. So, pushing to Backlog for future consideration when we go 2.1 or even 3.0.

artembilan avatar Sep 12 '24 16:09 artembilan