fix(stream): saturate pending_number decrements and clamp lag to INT64_MAX [FaaFyfxR9WAQrL7FcAgEHJvztd8cVMxvjHRS55rw1nwH] - #3589
Closed
waterWang wants to merge 1 commit into
Conversation
…4_MAX to prevent RESP integer overflow
|
Hi @waterWang, Thank you for your pull request. Please review our Contributing Guide. Please make sure you understand your changes and explain your reasoning in this pull request. Low-quality pull requests may be closed. |
Member
|
Closed due to AI policy. Feel free to reopen. |
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.
This PR addresses the remaining instances of the same failure class described in #3578 (merged): non-saturating
pending_numberdecrements andlagvalues exceedingINT64_MAX.Changes
1. Saturating
pending_numberdecrementsFollowing the pattern established in #3578, all remaining unconditional
-=operators onpending_numbernow use saturating arithmetic (clamp to 0):DeleteConsumer(XGROUP DELCONSUMER):group.pending_number -= deleted_pel— cross-level subtraction, highest risk since it subtracts a consumer's count from the group's count.DeletePelEntries(XACK):group.pending_number -= *acknowledgedandconsumer.pending_number -= ack_count.ClaimPelEntries(XCLAIM):original_consumer.pending_number -= 1.2. Clamp
lagtoINT64_MAXlagis auint64_tstored in group metadata, but it's emitted as a RESP integer that clients parse as signed 64-bit.entries_addedcan be set to anyuint64_tviaXSETID ... ENTRIESADDED n, so a correctly-computedlag = entries_added - entries_readcan legitimately exceedINT64_MAX.Both
CheckLagValidcomputations now clamp toINT64_MAXviastd::min.Verification
All changes follow the same saturating pattern from #3578:
No behavioral change for normal operation — clamping only activates on already-corrupt data or extreme
entries_addedvalues.