Repository navigation
Reset a CycleBuffer segment's start trim when it is recycled (#3302) - #3303
Merged
Merged
Conversation
Absorbed from PR #3251's branch (0ce150b), where its read/parse stress test found it. Segment.Recycle returns the segment to a process-wide spare slot, from which Segment.Create hands it to any buffer as pristine - but it kept StartTrimCount, and some paths recycle without Untrim first (Release, and AppendOrRecycle's search-exhausted path). The next buffer's 'new' segment then carried a trim that never happened: Debug.Assert(leasedStart == 0) in Debug, and in Release a later Untrim expanding backwards by it, corrupting the chain's running indexes. ARecycledTrimmedSegmentStartsCleanInTheNextBuffer: trim, Release, then a new buffer's first segment - StartTrimCount 4 on the old code, 0 now.
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.
Fixes #3302.
CycleBuffer.Segment.Recycle()returns segments to a process-wide_spareslot without resettingStartTrimCount, andCreate/Initdon't reset it either, so the next buffer to take that segment (any connection, any multiplexer) inherits a trim that never happened. Segments reach the slot still trimmed viaRelease()and viaAppendOrRecycle's search-exhausted path (afterResetAndGetNext, which restoresMemorybut not the trim) - the latter in steady state for multi-segment buffers, not just on teardown.The stale value bites in
Commit->CopyDueToDiscardDuringWrite: when the buffer is fully drained while a write lease is open (the outbound copy-out loop discarding while the writer holdsGetMemory),Untrimzeroes the trim and the copy reads fromleasedStart, which still includes the stale offset - so the wrong bytes go out.StartTrimCountinRecycle, plus its test.DiscardDuringWriteKeepsLeasedBytesAfterARecycledTrimmedSegment, which checks the bytes rather than the field: without the fix the second buffer commits789(the previous buffer's payload) instead ofXYZ.RESPite.Tests pass on net10.0 (1719/1719).