Skip to content

fix: release cache relay slots after write failures - #264

Merged
ovaistariq merged 5 commits into
mainfrom
perfloop-pr-open-3f7b77yfvf
Oct 21, 2026
Merged

ovaistariq merged 5 commits into
mainfrom
perfloop-pr-open-3f7b77yfvf

Conversation

@perfloop

@perfloop perfloop Bot commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

A whole-body cache write can return before the relay has consumed its pipe. The GET must still send the complete successful origin response, but a failed cache write can leave relay goroutines and a populate reservation alive. The relay now closes the cache-side pipe with the returned store error, cancels the detached context, and returns queued and listener buffers before releasing the reservation. Deadline errors reach the cache pipe as errors rather than clean EOF, preventing incomplete whole-body entries from being published. Block-mode writes retain their drain-on-error path. The README and architecture guide describe returned-error recovery and the limit when a store call never returns. No public API or configuration changed.

TestCacheableFullGet_StoreFailureReleasesRelayAndReservation injects failures before reading, after seven bytes, and after EOF through full GETs. On base 628616f, the before-read and partial-read cases fail while the after-EOF control passes. On intermediate repair fd85dea and final revision 264d0ed, all three pass. It checks the origin status, headers and bytes, terminal error observation, absent failed metadata, released count and byte reservations, and a later cache hit.

TestCacheableFullGet_DeadlineDoesNotPublishPartialBody verifies that a cache deadline cannot publish a truncated whole-body entry while the GET returns the complete origin response.

Revision raw_file subtest (128 KiB) inline subtest (40 KiB)
Base 628616f Pass Pass
Intermediate fd85dea 66,560 of 131,072 bytes visible under 131,072-byte metadata 33,280 of 40,960 bytes visible under 40,960-byte metadata
Final 264d0ed Pass Pass

The deadline test fills the 64-entry relay queue and uses Go virtual time with a cache-client double modeling the pinned local-CAS partial-read path; it resumes the store after the deadline. It does not promise termination if a store call never returns. Cache-focused embedded-store integration tests exercise normal whole-body and block-mode writes.

This condition holds with this change and does not hold at 628616fd9e19fac473837eb45eb46115e3d33313: For cacheable sub-block full-GET misses in non-tiered mode, once the whole-body cache writer has returned an error before reading, after a partial read, or after EOF and the successful client request has completed, no cache relay or populate reservation may remain live. The original cache error must be observed, no failed metadata may be visible, and a later healthy GET must populate; the first GET must preserve the origin status, headers, and bytes..

make test-proxy, the cache-focused embedded-store integration tests, make build, make lint-ci, and the affected tests under the race detector pass. The unfiltered make test suite remains target-CI work. The comparison harness is not included in the pull request, and injected failures do not measure their production frequency.


Generated by Perfloop.


Note

Medium Risk
Changes cache-miss populate lifecycle and error propagation in a hot path; incorrect teardown could leak memory or publish bad cache entries, but behavior is heavily regression-tested.

Overview
Fixes whole-object cache populate teardown when the store write fails or hits its deadline, so clients still get the full successful origin GET while relay goroutines, pooled buffers, and populate reservations are released reliably.

On cache write error, the relay now closes the pipe read end with the store error and cancels the populate context to unblock writers stuck on a partial read. Early exit (deadline or upstream error) drains the chunk queue and synchronously releases remaining listener buffers before the slot is freed; relay deadlines close the pipe with an error instead of a clean EOF so truncated bodies cannot publish metadata. README and architecture docs note best-effort population and that a store call that never returns has no completion guarantee.

Adds integration-style tests for injected PutStream failures (before read, partial read, after EOF) and for deadline-driven partial reads (inline and raw-file paths).

Reviewed by Cursor Bugbot for commit 264d0ed. Bugbot is set up for automated code reviews on this repo. Configure here.

@greptile-apps

greptile-apps Bot commented Oct 18, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[High impact] The PR appears safe to merge; no actionable new issue or repository-rule violation was found.

Summary

This PR releases cache-populate slots after returned write failures without changing the successful origin response.

  • A returned cache-write error frees the populate slot after relay cleanup.
  • Cache deadlines keep incomplete whole-body responses out of the cache.

The ancestry and merge-base checks passed. Review of new behavior used the changes since fd85dea. No previous review threads were supplied. Tests were inspected, not run during this review.

Reviews (2) · Last reviewed commit: "docs: document cache-write recovery" · Reviewed by Greptile

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Want higher recall? High effort reviews run extra passes and find more bugs. A team admin can switch effort levels in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit fd85dea. Configure here.

Comment thread proxy/caching.go Resolved
@perfloop

perfloop Bot commented Oct 18, 2026

Copy link
Copy Markdown
Contributor Author

Addressed in 264d0ed58afb08020f6ad87eabe7b68f3196e48b. Response to this feedback.

The cache deadline path is addressed in this update. The relay now closes the pipe with the deadline error instead of clean EOF, and the full-GET test verifies that a partial cache body cannot become visible.

@ovaistariq
ovaistariq merged commit 14d3418 into main Oct 21, 2026
11 checks passed
@ovaistariq
ovaistariq deleted the perfloop-pr-open-3f7b77yfvf branch October 21, 2026 05:41
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 21, 2026
@tigrisdata-argocd-bot

Copy link
Copy Markdown

🎉 This PR is included in version 1.22.3 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants