Don't recalculate num pending inline on consumer info#7758
Merged
neilalexander merged 2 commits intomainfrom Jan 23, 2026
Merged
Don't recalculate num pending inline on consumer info#7758neilalexander merged 2 commits intomainfrom
neilalexander merged 2 commits intomainfrom
Conversation
Signed-off-by: Neil Twigg <neil@nats.io>
37b2293 to
ae14fb9
Compare
Signed-off-by: Maurice van Veen <github@mauricevanveen.com>
MauriceVanVeen
approved these changes
Jan 23, 2026
| if o.sseq > state.LastSeq { | ||
| o.npc = 0 | ||
| } else if npc > 0 { | ||
| o.npc = int64(min(npc, state.Msgs, state.LastSeq-o.sseq+1)) |
Member
There was a problem hiding this comment.
Updated from min(npc, state.Msgs) to min(npc, state.Msgs, state.LastSeq-o.sseq+1), which means:
- our pending count can't be larger than the total amount of available messages
- our pending count can't be larger than if every single message from our pointer to the end of the stream would be delivered
wallyqs
pushed a commit
to wallyqs/nats-server
that referenced
this pull request
Jan 26, 2026
…ithAccurateNumPending() This test demonstrates that when npc underflows (is too low due to double-decrement race): - info() returns wrong value (20) because checkNumPending() only caps, never recalculates - infoWithAccurateNumPending() returns correct value (50) because it always calls streamNumPending() Key insight: After PR nats-io#7758, checkNumPending() no longer triggers recalculation when npc is below state.Msgs. This means underflow scenarios (npc too low) are not detected/corrected by info(). For accurate monitoring, use infoWithAccurateNumPending(). https://claude.ai/code/session_011PV3TqBnngV6caLgFPdirH
neilalexander
added a commit
that referenced
this pull request
Jan 26, 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.
Recalculating num pending inline on consumer info can make them considerably more expensive than intended and can result in unexpectedly taking out the lock on the underlying store of the stream, creating contention with other resources.
We will now only make simple adjustments just to make sure that the numbers aren't completely unrealistic. Num pending calculations still take place when becoming leader or updating the subject filters in the consumer config.
Signed-off-by: Neil Twigg neil@nats.io