Skip to content

GH-4444: Fix COUNT_TIME ack mode ignoring the time condition#1

Merged
serelli merged 2 commits into
mainfrom
GH-4444-count-time-ack-fix
May 26, 2026
Merged

GH-4444: Fix COUNT_TIME ack mode ignoring the time condition#1
serelli merged 2 commits into
mainfrom
GH-4444-count-time-ack-fix

Conversation

@serelli

@serelli serelli commented May 26, 2026

Copy link
Copy Markdown
Owner

Summary

Fixes spring-projects#4444.

In KafkaMessageListenerContainer.processCommits(), the if-else if structure caused timedAcks() to be unreachable for COUNT_TIME ack mode:

// BEFORE (broken): isCountAck is true for COUNT_TIME, so timedAcks() is never called
if (this.isCountAck) {
    countAcks();
}
else if (this.isTimeAck) {   // dead code for COUNT_TIME
    timedAcks();
}

For COUNT_TIME, both isCountAck and isTimeAck are true, so timedAcks() was never reached — only the count threshold was ever checked.

Fix

Split into two independent if checks so both conditions are evaluated:

if (this.isCountAck) {
    countAcks();
}
if (this.isTimeAck) {
    timedAcks();
}
else if (!this.isCountAck && !this.isManualImmediateAck) {
    commitIfNecessary();
    this.count = 0;
}

No double-commit risk: when countAcks() fires it resets last = now, so the subsequent timedAcks() call sees elapsed ≈ 0 and skips the commit.

Tests

Added testCountTimeAckModeCommitsOnTimeExpiry — a mock-based test that sets a large ackCount (1000, never reached) and a small ackTime (300 ms), then asserts that commitSync is called within 10 s purely from the time condition being satisfied.

🤖 Generated with Claude Code

serelli and others added 2 commits May 25, 2026 23:04
…dition

For COUNT_TIME mode, both isCountAck and isTimeAck are true. The
previous if-else-if structure caused timedAcks() to be unreachable
whenever isCountAck was true, so the time threshold was never checked.

Split into independent if blocks so both countAcks() and timedAcks()
run for COUNT_TIME. Double-commit is not possible: when countAcks()
fires it resets `last` to now, so the subsequent timedAcks() call sees
elapsed ≈ 0 and does not commit again.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Signed-off-by: sandeep erelli <sandeep.erelli@hotmail.com>
Verifies that ackTime-based commits fire for COUNT_TIME mode even
when ackCount has not been reached (the scenario broken before the fix).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Signed-off-by: sandeep erelli <sandeep.erelli@hotmail.com>
@serelli serelli force-pushed the GH-4444-count-time-ack-fix branch from ef10481 to 24cc5ac Compare May 26, 2026 06:05
@serelli serelli merged commit f7a219e into main May 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

KafkaMessageListenerContainer for ackMode=COUNT_TIME doesn't check ackTime

1 participant