Repository navigation
fix(linkbuffer): expose the flush node from GetBytes(nil) after head drain - #430
Open
linhongyu510 wants to merge 1 commit into
Open
linhongyu510 wants to merge 1 commit into
linhongyu510 wants to merge 1 commit into
Conversation
|
|
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.
What type of PR is this?
Which issue(s) this PR fixes
None filed previously.
Background
UnsafeLinkBuffer.GetBytes(p)documents: "If p is not passed, return all readable bytes." (PR #313 added thelen(p) == 0auto-size path to implement exactly this.)When
pis empty/nil, the auto-size branch sized the result slice to the number of nodes strictly betweenreadandflush:The subsequent loop then fills non-empty intermediate nodes and finally appends the
flushnode only ifi < len(p). Oncereadhas advanced past the leading empty/unmanaged head node (i.e. after the first real read/skip), every node betweenreadandflushis non-empty, soi == len(p)and theflushnode is silently dropped.Two concrete failure shapes:
read == flush(the steady state after the empty head drains): the counting loop never runs,n = 0,pis empty, and the finalif i < len(p)guard is0 < 0— soGetBytes(nil)returns nothing at all, even thoughLen() > 0andBytes()returns all the data.read != flushwith several non-empty nodes:GetBytes(nil)returns the intermediate nodes but drops the most recently flushed node.The existing
TestLinkBufferGetBytesdid not catch this because it never reads anything, soreadstays parked on the empty head node, which happened to reserve a slot for the flush node.Fix
When auto-sizing, count the non-empty nodes from
readup to and includingflush, so the flush node always has a reserved slot. This makesGetBytes(nil)content-equivalent toBytes()(which already special-casesread == flush). The caller-providedppath (used internally withbarriercapslots) is unchanged.Regression
TestLinkBufferGetBytesExposesAllAfterHeadDrainassertsGetBytes(nil)reconstructs exactlyBytes()for both shapes. On the unpatched tree it fails:and passes with the fix.
Testing
go test ./...(norace): okgo test -race ./...: okgo vet ./...: clean