fix(redisclient): bind the caller's context to the Redis socket read
Summary
go-redis hands context.Background() to the socket unless ContextTimeoutEnabled is set, so a per-call context deadline never bounded the Redis socket read: a stalled server held the call for the full read_timeout. LabKit v2.60.0 exposes the flag (labkit MR 717). This change sets it, hardwired and with no config or proto surface, on both purpose clients (NewJobsClient and NewCacheClient) through overridesToConfig, including the nil-overrides path.
With the flag on, a call's deadline is the earlier of its context deadline and now + read_timeout, so outer contexts such as the 500ms URL-cache op timeout and the IAM and negative-cache derived deadlines now cut the read.
The comments, metric Help text, docs, and the S25 (iam-relationships-client) spec and plan text that described the gap are corrected in the same change. The production redis.cache timeouts that #1393 lowers are a separate change and are not touched here.
Commits, in order:
- the shared
internal/testutilstalling Redis server (completes the handshake, parksGETandSET) - the failing tests, which are red on their own by design (the test-first commit)
- the one-line
fix(redisclient)that turns them green - the comment, doc, spec and plan corrections
- a one-line test comment fix from review
- a second round of doc corrections from review: the negative-cache duration Help text and observability row, the
read_timeoutreference row, the S05 (distributed-state) and S05-A (cache-abstractions) specs anddocs/dev/go-libraries.mdnow stating the hardwired flag, and the S25 stall-listener and Step 2#1393wording - hardening of the stalling Redis helper from review: it parks every non-handshake command, cleanup closes accepted connections and waits for its goroutines, and an invalid RESP length closes that one connection instead of panicking, with its own tests
- review-round fixes: the
read_timeoutreference row now says the value caps every read and is the whole bound only on calls without a deadline, the stalling-helper tests usetcandttnames, and theRedisClientOverridescomment inconfig.proto(comment only, with the regeneratedconfig.pb.go) and the S05 (distributed-state) spec list every field the override surface omits: the metric identity,ContextTimeoutEnabledandDisableClientCommands - review-round follow-ups:
docs/dev/go-libraries.mdnames the cost of the hardwired flag (a call cut by its deadline or a socket timeout closes its pooled connection, and the next call redials and repeats the handshake; LabKit exports no series that counts these closes, so watchpool_miss_totalrising whilepool_conn_total_currentchurns), and the stalling-helper tests give reply and EOF reads a 5s arrival ceiling while the parked cases keep the 100ms silence window
Asynq is affected only negligibly: its processor calls already pass deadline-carrying contexts, and its other loops use context.Background().
No plan file: this is a one-flag hardwire plus the corrections to text that described its absence, and the work item and its discussion are the design record.
Governing ADRs
None. The ADR mirror has no text on socket read timeouts, ContextTimeoutEnabled, or Redis call deadlines.
Testing
go test -raceoverinternal/redisclient,internal/testutil,internal/storage/middleware/urlcache,internal/iamandinternal/remote, and the fullgo test -race ./...suite, pass after rebasing onto current main.TestClients_ContextBoundsSocketReadbuilds real jobs and cache clients against the stalling server and asserts a 200ms context cuts the read well under the 2sread_timeout.TestURLFor_StalledRedisFallsBackWithinOpTimeoutdrives the real jobs client through the URL-cache middleware and asserts the driver URL is returned within the 500ms op timeout instead of waiting out the 5s default.TestOverridesToConfig_FieldMappingnow expects the flag, andTestOverridesToConfig_EnablesContextTimeoutcovers nil and empty overrides for both client names.- Before the fix the new tests fail for the intended reason: the reads ran to
read_timeout(about 2s and 5s against 1s and 2.5s caps). - Lint is clean (
mise exec -- golangci-lint run), also with the integration tag onredisclientandurlcache. - E2E catalogs (
docs/testing/): no scenario is added or affected. The change alters when an internal Redis call times out, with nothing observable from outside the service beyond the existing fallback behavior. docs/user/: not affected. No customer-visible surface, setting or limit changes;docs/dev/configuration-reference.mdis corrected to the as-is behavior.
Related to #1391 (closed)