Skip to content

fix(cache): bound each cache read with a size-scaled deadline - #270

Merged
ovaistariq merged 1 commit into
mainfrom
fix-cache-read-timeout
Oct 21, 2026
Merged

ovaistariq merged 1 commit into
mainfrom
fix-cache-read-timeout

Conversation

@ovaistariq

@ovaistariq ovaistariq commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

A stalled remote peer read (GetStream, GetRangeStream, including the byte-zero existence probes) held a request until the client disconnected or the server's 5-minute WriteTimeout fired; there was no per-read deadline on cache reads.

Every cache read in the proxy package now runs under a context.WithTimeout chosen by what consumes the bytes:

  • Reads into a buffer (small whole bodies, assembled and certified ranges, block slices for the pipelined and complete-entry paths) and existence probes use cacheReadTimeoutForSize: a 30-second floor plus one second per MiB, capped at 5 minutes; probes get the floor.
  • Reads that stream straight to the client (large whole bodies, serveRangeFromCache, the sequential block stream) use a flat 5 minutes, equal to the server WriteTimeout. The client paces those reads, so a size-scaled bound would cut off slow clients; the flat cap only restates the bound the server already enforces.

A deadline from either bound is an ordinary transient read error: bodyGone stays false so nothing is invalidated; pre-commit reads fall through to upstream; committed block streams take the existing byte-exact remainder salvage. No function signatures or configuration change.

Replaces #222, whose 242-line idle watchdog, per-write CAS and new config key are not adopted.

🤖 Generated with Claude Code

https://claude.ai/code/session_01NGTev5ePU5jHubGtdoUfK6


Note

Medium Risk
Touches all GetObject cache-serve and block-assembly paths with new deadlines; mis-tuning could cause extra upstream fallthrough, but timeouts are explicitly non-invalidating and client-paced streams keep the server WriteTimeout cap.

Overview
Bounds every proxy cache read with a per-operation context.WithTimeout, so a stalled remote peer gRPC read no longer holds requests until the client disconnects or the server’s 5-minute WriteTimeout.

Buffered reads and probes (small bodies, block assembly slices, BodyExistsErr / block presence checks) use cacheReadTimeoutForSize: a 30s floor plus one second per MiB, capped at 5 minutes. Reads whose sink is the HTTP client (large whole-body streams, range streams, sequential block streaming) use a flat cacheStreamReadTimeout (5 minutes, aligned with WriteTimeout) so slow clients are not cut off by size-scaled limits.

Block cache paths consolidate on getBlockRangeStream and probeBlock; parquet footer probing switches from BlockExists to probeBlock so probe stalls surface as errors, not “absent.” Timeouts are treated as transient (existing bodyGone / block salvage behavior): pre-commit paths fall through to upstream without invalidating metadata.

Adds cache_read_timeout_test.go covering stalled whole-body and block-probe fallthrough, and that client-paced streams are not canceled by the short size-scaled deadline.

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

A stalled remote peer read (GetStream / GetRangeStream, including the
[0,0] presence probes) held a request until the client disconnected or
the server's 5-minute WriteTimeout fired: cache reads had no deadline
of their own.

Give every cache read in the proxy its own context.WithTimeout. Reads
that land in a buffer, and presence probes, use cacheReadTimeoutForSize,
the read-side twin of cacheWriteTimeoutForSize: a 30s floor plus one
second per MiB, capped at the server WriteTimeout (5m); probes get the
floor. Reads whose sink is the client (the large streamed whole-body
serve, serveRangeFromCache, streamBlockRangeSequential) are paced by
that client, so a size-scaled bound would cut off a slow-but-progressing
client earlier than the server does today; they use the flat
cacheStreamReadTimeout (5m), which only restates the server's
WriteTimeout. A shorter parent deadline still wins everywhere.

Call sites: serveFromCache (buffered small body: sized; streamed large
body: flat), serveRangeFromCache (flat), every block payload read
through the new getBlockRangeStream seam (assembled, certified,
pipelined, complete-from-blocks and post-fetch re-reads: sized;
sequential direct-to-client: flat), and the presence probes through
probeBlock (ensureBlocksCached, runBlockFetch, parquet footer) plus
entryServable's body probe (floor).

A timeout is an ordinary transient read error on every path: bodyGone
and the block-stream salvage already treat context.DeadlineExceeded as
not-evidence-of-eviction, so the entry is never invalidated, a committed
block stream is completed from upstream exactly as for any other read
error, and a pre-commit failure falls through upstream.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NGTev5ePU5jHubGtdoUfK6
@greptile-apps

greptile-apps Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge.

Summary

Adds per-read deadlines to proxy cache reads.

  • Proxy cache reads now stop at deadlines matched to where their bytes go.

No actionable issues found. Review used source inspection; tests were not run.

Reviews (1) · Last reviewed commit: "fix(cache): bound each cache read with a..." · Reviewed by Greptile

@ovaistariq
ovaistariq merged commit d5e2fe9 into main Oct 21, 2026
11 of 12 checks passed
@ovaistariq
ovaistariq deleted the fix-cache-read-timeout branch October 21, 2026 19:43
@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.

2 participants