Skip to content

fix: wait for bulk-delete cache fences before responding - #238

Merged
ovaistariq merged 10 commits into
mainfrom
perfloop-pr-open-r56t5fkvfk
Oct 21, 2026
Merged

ovaistariq merged 10 commits into
mainfrom
perfloop-pr-open-r56t5fkvfk

Conversation

@perfloop

@perfloop perfloop Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Bulk DeleteObjects could send a complete 2xx response before TAG finished the second cache invalidation intended to remove a racing GET refill. The client could receive success while that stale refill remained available.

For cache-enabled requests with a parsed nonempty key list, TAG captures upstream status, headers, and body before publishing them. On 2xx, existing per-key result rules select the invalidations; TAG commits after those attempts return. Keys whose requested entries all failed are skipped, and an unparseable result retains the conservative all-key fallback. Cache-disabled, malformed-request, and empty-key requests keep direct streaming. The README and cache/S3 docs describe this ordering.

TestBulkDeleteResponseWaitsForPostSuccessFence drives the registered handler and transparent forwarder with a local upstream, concurrent GET, and held tombstone. It checks the complete response bytes and the GET after completion. TestBulkDeleteWithCacheDisabledKeepsStreaming verifies that the first response byte reaches the client before the upstream body finishes; it passes on the base and final source. The proxy tests TestHandleDeleteObjects_PartialFailureKeepsFailedKeyRefill, TestHandleDeleteObjects_MixedVersionSuccessReinvalidatesKey, and TestHandleDeleteObjects_VersionIdMismatchFailureKeepsRefill cover per-key results. TestHandleDeleteObjects_UnparseableResultInvalidatesAllAndPreservesResponse, TestHandleDeleteObjects_UpstreamFailurePreservesResponseAndRefill, and TestHandleDeleteObjects_IncompleteCapturePreservesPrefixAndInvalidatesKey cover byte-exact output and fallback behavior; they pass against the base production code and final source. TestDeleteObjectsResponseStagerCountsClientAcceptedBytes checks staged and direct output accounting.

handlers/delete_objects_fence_benchmark_test.go::BenchmarkBulkDeleteResponseCompletion is a checked-in Go testing.B benchmark, run with the repository's ordinary go test -bench command. It measures the cached route through the registered handler and transparent forwarder, seeds a cache entry outside timing, reads a fixed-length 128 KiB-padded result to EOF, and waits for handler cleanup outside the timed span. Its in-memory cache and local upstream are a controlled fixture, not a production response-size distribution or latency estimate; no performance claim or threshold is made.

The integration test tests/integration/cache_test.go::TestCache_InvalidateOnDeleteObjects did not pass reliably here on either source revision because embedded-cache memberlist address discovery could not consistently find a private IP in this sandbox. Target CI should run it.

This deliberately delays delivery while the upstream response is captured and, on 2xx, while invalidation attempts return. Proxy-mode invalidation has no cache-operation deadline; a nonreturning call can keep the response open. Returned backend failures retain the existing best-effort retry and may leave stale metadata until TTL. Buffer lifetime remains unmeasured.

The build, lint, vet, scoped handler/proxy unit and race tests, and benchmark smoke run passed locally. The default-profile S3 tests s3tests/functional/test_s3.py::test_multi_object_delete and test_multi_objectv2_delete, plus SDK tests TestSDK_DeleteObjects and TestSDK_DeleteObjects_WithCache, were not run because this environment has no AWS credentials or local TAG service; the repository's S3 workflow should run them with its configured Tigris service and credentials.

This condition holds with this change and does not hold at 0126eeb4e2e093fa2b0ada2ee0a5464069f3a1e1: For a cache-enabled transparent POST /{bucket}?delete with one parsed key, successful cache operations, a fixed-length complete non-quiet 2xx DeleteResult reporting that key deleted, and a GET that refills its old object during the upstream delete, the client cannot finish the 2xx response until the key's post-success cache fence completes; a GET after that response cannot serve the stale refill..


Generated by Perfloop.


Note

Medium Risk
Changes DeleteObjects response timing and cache consistency semantics for bulk deletes; incorrect fencing could delay clients up to 10s or briefly serve stale cache if invalidation stalls.

Overview
Fixes a read-after-write gap where cache-enabled DeleteObjects could finish streaming a successful 2xx while a racing GET had refilled stale data that the post-success invalidation had not yet cleared.

For requests with a parsed nonempty key list and cache on, TAG now captures the upstream status, headers, and body via a response stager instead of writing to the client during ForwardWithCapture. On upstream 2xx it runs the existing per-key post-success invalidation (success-only keys, conservative fallback when the XML is unparseable) under a shared 10s deadline with context.WithoutCancel, then commits the captured response. Cache-disabled, malformed, or empty-key requests still stream directly. If the fence does not finish in time, TAG logs a warning and still returns the upstream 2xx; skipped keys may stay stale until TTL. The forwarder defers outbound byte metrics until staged responses are committed.

Docs in README, cache-control.md, and s3-compatibility.md describe the new ordering. Tests and a benchmark cover fence ordering, partial failures, upstream errors, stalled cache peers, and metric accounting.

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

@greptile-apps

greptile-apps Bot commented Sep 28, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no new actionable issue was established.

Summary

Cache-enabled bulk DeleteObjects requests now hold the upstream response until the post-success cache attempts return.

  • Cached bulk deletes wait for their cache fences before replying.

Reviews (7) · Last reviewed commit: "Merge origin/main into perfloop-pr-open-..." · Reviewed by Greptile

@greptile-apps

This comment has been minimized.

@perfloop
perfloop Bot force-pushed the perfloop-pr-open-r56t5fkvfk branch from 929e5eb to 4412b33 Compare October 21, 2026 13:43
ovaistariq and others added 2 commits October 21, 2026 10:12
HandleDeleteObjects now stages the captured DeleteResult until the
post-success cache fence returns, so a stalled cache peer would hold the
client's 2xx indefinitely: the fence ran under context.Background() with
no deadline where main had run it after the response was already sent.

Run the proxy-mode fence under a context derived from the request but
detached from its cancellation (context.WithoutCancel, so a client that
disconnects after upstream committed the delete does not abandon the
fence) and bounded by bulkDeleteFenceTimeout (10s, matching the tiered
converge's per-key bound). When the deadline fires the remaining per-key
attempts fail fast, the captured upstream 2xx is still committed, and a
Warn with the bucket and fenced key count records that the fence did not
converge; stale metadata ages out via TTL as before. A timeout is never
turned into a client-visible error.

Add a synctest-driven test with a cache client that stalls every
post-forward meta delete until its context ends: the response is released
exactly at the fence deadline, is the byte-exact upstream 200, and the
timeout warning carries the bucket and key count. Without the bound the
test's bubble deadlocks.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NGTev5ePU5jHubGtdoUfK6
(cherry picked from commit e470f5acef0931fcbda49b97d26819029dc8c6c9)

@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 716199d. Configure here.

Comment thread proxy/delete_objects.go Resolved
ovaistariq and others added 2 commits October 21, 2026 11:51
The tiered helper runs under its own per-key timeout, so a large tiered batch
could hold the staged 2xx for N times that timeout regardless of the shared
fence deadline. Check the shared deadline before each key in both modes and
report the keys skipped in the timeout warning.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NGTev5ePU5jHubGtdoUfK6
Comment thread docs/cache-control.md Resolved

@ovaistariq ovaistariq left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reviewed: bulk DeleteObjects now stages the upstream response and runs the post-success per-key fences before committing the 2xx, so a GET refilling the old object during the delete cannot stay servable after the client has its success. Fence bounded by a shared 10-second deadline in both modes with skipped keys counted in the warning; docs aligned.

@ovaistariq
ovaistariq merged commit 2289e30 into main Oct 21, 2026
9 checks passed
@ovaistariq
ovaistariq deleted the perfloop-pr-open-r56t5fkvfk branch October 21, 2026 21:19
@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