Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

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

Open
yahyaoo opened this issue Nov 6, 2020 · 2 comments
Milestone

Comments

@yahyaoo
Copy link

yahyaoo commented Nov 6, 2020

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
Copy link
Author

yahyaoo commented Nov 6, 2020

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);
    }

@artembilan
Copy link
Member

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 artembilan added this to the Backlog milestone Sep 12, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants