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/testutil stalling Redis server (completes the handshake, parks GET and SET)
  • 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_timeout reference row, the S05 (distributed-state) and S05-A (cache-abstractions) specs and docs/dev/go-libraries.md now stating the hardwired flag, and the S25 stall-listener and Step 2 #1393 wording
  • 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_timeout reference row now says the value caps every read and is the whole bound only on calls without a deadline, the stalling-helper tests use tc and tt names, and the RedisClientOverrides comment in config.proto (comment only, with the regenerated config.pb.go) and the S05 (distributed-state) spec list every field the override surface omits: the metric identity, ContextTimeoutEnabled and DisableClientCommands
  • review-round follow-ups: docs/dev/go-libraries.md names 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 watch pool_miss_total rising while pool_conn_total_current churns), 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 -race over internal/redisclient, internal/testutil, internal/storage/middleware/urlcache, internal/iam and internal/remote, and the full go test -race ./... suite, pass after rebasing onto current main.
  • TestClients_ContextBoundsSocketRead builds real jobs and cache clients against the stalling server and asserts a 200ms context cuts the read well under the 2s read_timeout.
  • TestURLFor_StalledRedisFallsBackWithinOpTimeout drives 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_FieldMapping now expects the flag, and TestOverridesToConfig_EnablesContextTimeout covers 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 on redisclient and urlcache.
  • 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.md is corrected to the as-is behavior.

Related to #1391 (closed)

Edited by David Fernandez

Merge request reports

Loading
Loading