Repository navigation
Skip sleep for non-positive back off intervals - #4897
Merged
sobychacko merged 1 commit intoNov 9, 2026
Merged
Conversation
ListenerUtils.conditionalSleep() and conditionalSleepWithPoll() sleep one slice (SMALL_SLEEP_INTERVAL, 10 ms) before checking the deadline, so an interval of 0 still sleeps about 10 ms. With the default SeekUtils.DEFAULT_BACK_OFF, FixedBackOff(0, 9), which the reference docs describe as "no back off", DefaultErrorHandler slept 10 ms on each of the 9 retries via DefaultBackOffHandler, about 90 ms per failing record. DefaultAfterRollbackProcessor.processBatch() and the batch retry in ErrorHandlingUtils.retryBatch() paid the same 10 ms per retry with a zero interval. Return immediately for a non-positive interval, as unrecoverableBackOff() already does with its interval > 0 check. The sleep dates back to spring-projectsGH-1480, when stoppableSleep() replaced Thread.sleep(nextBackOff) in FailedRecordTracker, and spring-projectsGH-1845, which reduced the slice from 100 ms to 10 ms. Signed-off-by: Dongmin Kim <m914@naver.com>
spring-builds
pushed a commit
that referenced
this pull request
Nov 9, 2026
Fixes: #4897 ListenerUtils.conditionalSleep() and conditionalSleepWithPoll() sleep one slice (SMALL_SLEEP_INTERVAL, 10 ms) before checking the deadline, so an interval of 0 still sleeps about 10 ms. With the default SeekUtils.DEFAULT_BACK_OFF, FixedBackOff(0, 9), which the reference docs describe as "no back off", DefaultErrorHandler slept 10 ms on each of the 9 retries via DefaultBackOffHandler, about 90 ms per failing record. DefaultAfterRollbackProcessor.processBatch() and the batch retry in ErrorHandlingUtils.retryBatch() paid the same 10 ms per retry with a zero interval. Return immediately for a non-positive interval, as unrecoverableBackOff() already does with its interval > 0 check. The sleep dates back to GH-1480, when stoppableSleep() replaced Thread.sleep(nextBackOff) in FailedRecordTracker, and GH-1845, which reduced the slice from 100 ms to 10 ms. Signed-off-by: Dongmin Kim <m914@naver.com> (cherry picked from commit 8bfed6a)
spring-builds
pushed a commit
that referenced
this pull request
Nov 9, 2026
Fixes: #4897 ListenerUtils.conditionalSleep() and conditionalSleepWithPoll() sleep one slice (SMALL_SLEEP_INTERVAL, 10 ms) before checking the deadline, so an interval of 0 still sleeps about 10 ms. With the default SeekUtils.DEFAULT_BACK_OFF, FixedBackOff(0, 9), which the reference docs describe as "no back off", DefaultErrorHandler slept 10 ms on each of the 9 retries via DefaultBackOffHandler, about 90 ms per failing record. DefaultAfterRollbackProcessor.processBatch() and the batch retry in ErrorHandlingUtils.retryBatch() paid the same 10 ms per retry with a zero interval. Return immediately for a non-positive interval, as unrecoverableBackOff() already does with its interval > 0 check. The sleep dates back to GH-1480, when stoppableSleep() replaced Thread.sleep(nextBackOff) in FailedRecordTracker, and GH-1845, which reduced the slice from 100 ms to 10 ms. Signed-off-by: Dongmin Kim <m914@naver.com> (cherry picked from commit 8bfed6a)
This was referenced Nov 9, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ListenerUtils.conditionalSleep()andconditionalSleepWithPoll()sleep one slice (SMALL_SLEEP_INTERVAL, 10 ms) before they check the deadline, so an interval of 0 still sleeps about 10 ms. With the defaultSeekUtils.DEFAULT_BACK_OFF(FixedBackOff(0, 9)), which the reference docs describe as "no back off",DefaultErrorHandlersleeps 10 ms on each of the 9 retries viaDefaultBackOffHandler, about 90 ms per failing record on top of the seek and re-poll (measured 109 ms for 9 retries with a running container, 5 ms withcontainer == null).DefaultAfterRollbackProcessor.processBatch()(withcommitRecoveredandbatchRecoverAfterRollback) and the batch retry inErrorHandlingUtils.retryBatch()pay the same 10 ms per retry with a zero interval.Cause: both methods are
do/whileloops whose first statement isThread.sleep(sleepInterval), so the deadline is only checked after a full slice.unrecoverableBackOff()already guards itsstoppableSleep()call withinterval > 0, and thecontainer == nullbranch ofDefaultBackOffHandlercallsThread.sleep(0), which does not sleep; the other two entry points had no such check.Changes:
conditionalSleep()andconditionalSleepWithPoll()wheninterval <= 0, and say so in their Javadoc.Tests (
ListenerUtilsTests, no timing assertions; all three fail onmain):conditionalSleepWithNonPositiveInterval: the condition supplier is never evaluated for0and-1.conditionalSleepWithPollWithNonPositiveInterval: the supplier is never evaluated and the consumer is never polled.stoppableSleepWithZeroInterval:container.isRunning()is never called.The full
:spring-kafka:testsuite passes locally with the change (1278 tests, 4 skipped).Notes:
conditionalSleepWithPoll()already skipped the poll on its first iteration, so for a zero interval it never polled before this change either; consumer liveness inretryBatch()is unchanged.container == nullbranch and the docs already describe. Users who implicitly relied on the 10 ms pacing ofFixedBackOff(0, n)batch retries will see a tighter loop.The zero-interval sleep dates back to GH-1480, which replaced
Thread.sleep(nextBackOff)inFailedRecordTrackerwithstoppableSleep()without the> 0guard thatunrecoverableBackOff()kept, and GH-1845, which lowered the slice from 100 ms to 10 ms for intervals up to 500 ms; GH-3885 copied the loop intoconditionalSleepWithPoll(). TheFixedBackOff(0L, 2L)samples inannotation-error-handling.adoc("recover after 3 failures, with no back off") and theSeekUtils.DEFAULT_BACK_OFFJavadoc ("0 interval") already describe the intended behavior, so no docs change is included.