Prevent max message cache size reaching zero by having a minimum of 1 message per worker after the round up#424
Merged
Emanuele Sabellico (emasab) merged 3 commits intomasterfrom Dec 19, 2025
Conversation
There was a problem hiding this comment.
Pull request overview
This PR addresses a potential edge case where the message cache size could be calculated as zero, leading to fetch failures. The fix ensures that each worker has at least one message in the cache while maintaining the existing round-up logic.
Key changes:
- Introduces a
Math.max()check to guarantee a minimum of 1 message per worker before applying concurrency multiplier - Refactors the rounding logic into a separate
#roundUpToNearestMultipleOfMaxBatchesSizemethod for better code organization - Updates CHANGELOG to document the fix
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| lib/kafkajs/_consumer.js | Adds minimum message guarantee and extracts rounding logic into helper method |
| CHANGELOG.md | Documents the bug fix for low consumption rate scenarios |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
ea75d1a to
9f624a5
Compare
9f624a5 to
2389348
Compare
having a minimum of 1 message per worker after the round up
2389348 to
aa9d606
Compare
Pranav Rathi (pranavrth)
requested changes
Dec 19, 2025
lib/kafkajs/_consumer.js
Outdated
| 1, | ||
| // Messages needed for `#maxCacheSizePerWorkerMs` milliseconds of consumption | ||
| // per worker | ||
| Math.round( |
There was a problem hiding this comment.
We can use Math.ceil here instead.
Contributor
Author
There was a problem hiding this comment.
yes, not a big change to always take the ceil given it's also rounding up to next multiple of maxBatchSize later
Pranav Rathi (pranavrth)
requested changes
Dec 19, 2025
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.
Continuation of #418 with this different approach that allows to