Repository navigation
fix: prevent partial whole-object cache entries - #263
Merged
Merged
Conversation
Signed-off-by: Perfloop Agent <[email protected]>
Signed-off-by: Perfloop Agent <[email protected]>
Signed-off-by: Perfloop Agent <[email protected]>
Signed-off-by: Perfloop Agent <[email protected]>
[Medium impact] The PR appears safe to merge; no blocking issues were found. SummaryThe PR prevents failed whole-object broadcasts from looking like successful cache writes.
No actionable new issues were found. No previous Greptile threads were supplied. Reviews (2) · Last reviewed commit: "fix(broadcast): surface listener errors ..." · Reviewed by Greptile |
Conflicts resolved: README.md keeps both appended lines; broadcaster.go Complete() uses the PR's closeWithError with main's b.err; caching.go keeps the PR's cachePipeReadError wrapping alongside main's relayErr branch.
PR #263 fixed two real bugs: a slow-consumer disconnect dropped its ErrSlowConsumer on the floor when the listener's buffer was full (so the cache listener drained to a clean close and committed a truncated body under the full Content-Length), and an upstream mid-body drop surfaced as io.ErrUnexpectedEOF, which the ocache backend accepted as "small value, done". The cachePipeReadError wrapping for the second bug is kept as is. Its fix for the first bug was unsafe: closeWithError made room for the error chunk by receiving one queued chunk. Channels are FIFO, so that removed the OLDEST unread chunk, and a consumer that had read chunks 0..k-1 next received k+1 at k's offset - wrong bytes on the wire before the error arrived. Replace the displacement with a terminal-error field on Listener: - closeWithError now records the error in Listener.termErr (written under Broadcaster.mu before close(ch)), tries a best-effort non-blocking send of Chunk{Err: err}, and closes the channel. Queued data chunks are never dropped or reordered. - Listener.Err() exposes the terminal error. It is valid once Chunks() has closed: the close happens-before the receive that observes it, so consumers read it without extra locking after their range loop ends. - Both consumers honour it. writeChunksToResponse (client path) returns Err() after the loop exactly as it would an error chunk, so a disconnected client never gets a clean EOF with a short body. setupCacheListener (cache path) sets chunkErr from Err() when the loop ended on a clean close, so the pipe fails and no metadata is committed. - Subscribe's already-done path records termErr too, for consistency. Defense in depth: PutWithMetaStreamIfVersion now counts the bytes the store consumed and refuses the meta commit with ErrBodyLengthMismatch when they differ from meta.ContentLength (short or long), mirroring the io.ReadFull guard in putBlocksFromStream. This closes the root cause behind #251 and #249 even if some future producer loses the error signal. The versioned body is left to age out via TTL, as with a lost precondition. Tests: the slow-consumer test now reads Err() after the loop (the error chunk is best-effort on a full queue); new broadcaster tests assert that a full-buffer disconnect delivers every queued chunk in order with no hole and then surfaces the error via Err(), and that a failed Complete on a full queue does the same; new cache tests assert a short or long body is not committed and an exact or unknown length still is. The PR's handler-level tests pass unchanged. Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01NGTev5ePU5jHubGtdoUfK6
This was referenced Oct 21, 2026
ovaistariq
added a commit
that referenced
this pull request
Oct 21, 2026
Route every broadcast disconnect through Listener.closeWithError: the disconnectSlowConsumer helper used by both the copying Broadcast path and the ownership-transferring broadcastOwnedLocked path now records termErr, queues a best-effort error chunk, and closes the channel without displacing queued data. Complete() keeps #260's headerCh/headerErr behaviour and #263's closeWithError completion. On the owned path a chunk rejected by a full owner queue is never queued, so the caller keeps and releases that buffer; a chunk already queued stays with its listener and is released by the consumer's drain. Adds a test pinning that owned-path disconnect contract. Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01NGTev5ePU5jHubGtdoUfK6
ovaistariq
approved these changes
Oct 21, 2026
|
🎉 This PR is included in version 1.22.3 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
A full-object GET miss streams the origin body to the client and a bounded cache listener. If the listener queue fills or the upstream body read fails, losing the terminal error can make the stream look complete to the cache and publish a prefix under full-object metadata.
The broadcaster now reserves a queue slot for the terminal error by returning one displaced pooled buffer before closing a failed listener. Clean completion keeps all queued data. The cache pipe wraps EOF-shaped terminal failures so the embedded store cannot mistake
io.ErrUnexpectedEOFfor a normal short inline value. The README and cache-control guide describe the behavior; no public API, configuration, or schema changes.The new routed
TestBroadcastErrorsDoNotPublishIncompleteWholeObjectwas added with this change. It fails on the test-only comparison because both terminal-error paths leave an incomplete entry visible, and passes on final; it checks the cache state, a complete client response on the slow-cache path, and the later healthy GET. The new controlTestBroadcastCompletionKeepsFullQueuedBodypasses on both the test-only comparison and final. The originalTestBroadcasterSlowConsumerDisconnectpassed on base while allowing a clean close; its tightened version failed on the test-only comparison withnilinstead ofErrSlowConsumerand passes on final with the terminal error. ExistingTestCacheableFullGet_SubsequentRequestHitsCache,TestServeAssembledRange_RemoteMissRejectsShortValidatedBlock, andTestETagVersionedBody_VersionsCoexistUntilTTLpassed in the scoped suites. The routed test uses an in-memory cache fixture that mirrors the pinned embedded store's inline handling ofio.ErrUnexpectedEOF.The proxy, handler, and cache package tests, the proxy/handler race run,
make lint-ci, andmake buildpassed. The full repositorymake testandmake test-integrationsuites were not run here; they remain target-CI work. The comparison runner is not included in the pull request; the native tests it runs are. Production frequency has not been measured.This condition holds with this change and does not hold at
41d4f6941b3e18d7ac53ffdd8a0dafc1b94be943:For TAG's cacheable whole-object HTTP GET misses with an unchanged metadata version token, both a slow-listener drop and an upstream body-read error must make the cache write fail and must not publish a partial body under complete-object metadata; a healthy client still receives the full body when only its cache listener is dropped, and the next healthy GET returns the full body..Generated by Perfloop.
Note
Medium Risk
Changes correctness-sensitive whole-object cache populate and broadcast disconnect semantics; wrong handling could still serve truncated responses to slow clients or skip caching when healthy.
Overview
Fixes a bug where whole-object cache populate could commit metadata for a truncated body when the broadcast stream ended badly but looked like a clean EOF.
Broadcaster: Adds
Listener.Err()andcloseWithError, which always records the terminal result on the listener and only sends an error chunk when the queue has room—queued data chunks are never dropped or reordered (replacing behavior that could swap in an error chunk and skip bytes). Cache and GET handlers consultErr()after the chunk channel closes when no error chunk was delivered (e.g. slow-consumer disconnect with a full buffer).Cache populate path: Treats that terminal error like an in-stream failure, wraps EOF-shaped errors via
cachePipeReadErrorso inline storage cannot treatio.ErrUnexpectedEOFas a normal short value, andPutWithMetaStreamIfVersionrefuses to write metadata unless streamed bytes matchContent-Length(ErrBodyLengthMismatch).Docs/tests: README and
docs/cache-control.mdstate that failed cache listeners or upstream body errors do not publish partial entries; integration-style handler tests and unit tests cover slow listener, upstream failure, full-queue success, and length mismatch.Reviewed by Cursor Bugbot for commit 3daad57. Bugbot is set up for automated code reviews on this repo. Configure here.