Skip to content

[yumin-xia] feat(wicked): pass query timeouts to wpgx as database timeouts - #25

Merged
Stumble merged 5 commits into
mainfrom
yumin-xia/db-timeout-after-acquire
Nov 22, 2026
Merged

Stumble merged 5 commits into
mainfrom
yumin-xia/db-timeout-after-acquire

Conversation

@Stumble

@Stumble Stumble commented Nov 20, 2026

Copy link
Copy Markdown
Owner

Summary

  • Generated methods (:one, :many, :exec, :execrows, :execresult, :copyfrom, Each) pass their -- -- timeout to wpgx.WithDBTimeout instead of starting context.WithTimeout at the top. The timeout therefore bounds database work: it starts once the query has a pooled connection (wpgx waits at most max(T, AcquireTimeout), default 2s) and no longer covers the wait for a connection or the cache lookup, which is bounded by the Redis client's own timeouts.
  • Annotation syntax and generated signatures are unchanged; regenerated code requires the wpgx release with WithDBTimeout (compile-time check). Old generated code keeps its behavior with new wpgx.

Architecture and Key Decisions

  • Each visitors receive the statement context from wpgx rows (qctx is reassigned, so no new local can collide with a SQL parameter) and report through wpgx.StatementErr: an expired statement context, a visitor returning that deadline, and a drain that outlasts the timeout after an early stop match wpgx.ErrDBTimeout; other errors stay primary.
  • wpgx is a reserved identifier (a parameter named wpgx becomes wpgx_), because method bodies now call the package.
  • GUIDE.md documents the semantics; local record docs/changelogs/2026-11-20-db-timeout-after-acquire.md (primary design record in [yumin-xia] feat: start the database timeout after a connection is acquired wpgx#24).

Risks and Remaining Work

  • The endtoend module pins the wpgx branch commit (v0.5.2-0.20261120053742-4b29cac2136d) and the wicked CI job checks out the bookstore PR commit 89b3fbc; before merge, bump both to the wpgx tag and the merged bookstore commit.
  • The Redis-client bound for cache lookups needs dcache v0.3.0+ without Redis single flight (its default, what Alva services run); documented in the guide.

Breaking Changes

Regenerating changes the generated code (the timeout no longer covers waiting for a connection or the cache lookup) and requires the new wpgx. No signature changes.

Database Migrations

None.

Verification

  • go test -p=1 ./internal/codegen/wicked ./internal/cmd; go test -run 'TestReplay/base/' ./internal/endtoend (with this repo's sqlc-gen-json): pass.
  • internal/endtoend/testdata: CGO_ENABLED=0 go build ./...; SQLC_EACH_TEST_DSN=… go test -race ./wicked_compat/go: pass, including new PostgreSQL checks (TestGeneratedTimeoutPostgres: a 1.3s wait does not fail a 1s query, visitor deadline, visitor/drain timeouts, a lock-blocked query reports wpgx.ErrDBTimeout). Mutation checks: the v2.5.0 generated Each fixture and the pre-fix Each lines fail them.
  • Wicked CI bookstore job reproduced on a clean clone of bookstore 89b3fbc.
  • Not run locally: the full --tags=examples ./... suite (needs MySQL/PostgreSQL services); CI runs it.
  • Independent Codex review in five rounds; final ACCEPT of this content.

Merge Order

  1. [yumin-xia] feat: start the database timeout after a connection is acquired wpgx#24, then tag wpgx.
  2. [yumin-xia] test: regenerate with database timeouts that start after acquire bookstore#3 after bumping its wpgx pin.
  3. This PR after bumping the testdata pin and the bookstore ref; then tag sqlc.

Related PRs

🤖 Generated with Claude Code

Stumble and others added 5 commits November 20, 2026 05:14
Generated methods call wpgx.WithDBTimeout instead of starting their own
deadline, so the timeout starts once the query has a connection and no
longer covers waiting for one or the cache lookup. Each visitors receive
the statement context from wpgx rows.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Each reuses qctx for the statement context instead of declaring a new local,
and a parameter named wpgx is generated as wpgx_. Document that the cache
bound needs dcache without Redis single flight.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A visitor returning the statement deadline and a drain that outlasts the
database timeout after an early stop both fail with wpgx.ErrDBTimeout, as
the previous Each failed when its query context expired.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The generated code needs wpgx.WithDBTimeout. Pin the wpgx branch commit in
the endtoend module and run the bookstore contracts at the commit
regenerated with this generator, until wpgx is tagged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant