fix: prevent double-skip in revalidate path by clearing fillRange context#59
Merged
Conversation
…text before lazyRespond When revalidating a range request, lazilyRespond already applies correct range trimming via SkipReadCloser. The subsequent fillRange.PostRequest wrapped the body again with RangeReader, causing a double skip that resulted in unexpected EOF. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a double range-trim bug in the revalidate path. When a 304 revalidation produces a 206 from cache via lazilyRespond, lazilyRespond already trims the body to the requested offset using SkipReadCloser/LimitReadCloser. The downstream fillRange.PostRequest would then wrap the same body again with RangeReader, skipping additional bytes and causing data misalignment / "unexpected EOF". The fix clears the fillRangeKey value in the request context before calling lazilyRespond, so fillRange.PostRequest's frk != nil guard short-circuits.
Changes:
- In
RevalidateProcessor.revalidate, before serving a range-aware 304 hit vialazilyRespond, mutate the request's context to remove thefillRangeKeyvalue, sofillRange.PostRequestskips itsRangeReaderwrapping.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Summary
lazilyRespond和fillRange.PostRequest对响应 body 双重 skip 导致 unexpected EOF 的问题revalidate()调用lazilyRespond前清除 request context 中的fillRangeKey,防止fillRange.PostRequest重复应用RangeReaderRoot Cause
lazilyRespond从缓存块构建 206 响应时已通过SkipReadCloser将 body 定位到正确的起始偏移量,但fillRange.PostRequest在 post process chain 中再次用RangeReader裁剪同一偏移量,造成数据错位。Test plan
Closes #58
🤖 Generated with Claude Code