Skip to content

v0.6.0

Latest

Choose a tag to compare

@Stumble Stumble released this 22 Nov 08:02
3673ea0

Added

  • wpgx.WithDBTimeout(ctx, name, timeout): a database timeout for the statement named name. It starts once the statement has a connection (immediately inside a transaction) and lasts until the connection is free again (Exec/CopyFrom/Row.Scan returns, or the Rows are read to the end or closed). Waiting for a pool connection no longer counts against it. Wicked sqlc v2.6.0 generates it for every query's timeout option.
  • Pool wait bound: a statement with a database timeout waits at most max(timeout, AcquireTimeout) for a connection. AcquireTimeout (env POSTGRES_ACQUIRETIMEOUT) defaults to 2s, so no new configuration is needed.
  • Optional MaxAcquireWaiters (env POSTGRES_MAXACQUIREWAITERS, default 0 = no cap): extra waiters fail fast with ErrTooManyAcquireWaiters.
  • Errors ErrAcquireTimeout and ErrDBTimeout tell the two phases apart; both still match context.DeadlineExceeded. wpgx.StatementErr(ctx, err) marks a deadline error from a statement context with ErrDBTimeout.
  • Metrics: wpgx_acquire_wait_milliseconds{app,replica}, wpgx_db_latency_milliseconds{app,op,replica}, wpgx_timeout_total{app,op,replica,phase=acquire|db}, new wpgx_conn_pool ops (acquire_waiting, acquire_rejected_count, empty_acquire_count, empty_acquire_wait_seconds, canceled_acquire_count, new_conns_count), and the span attribute wpgx.acquire_wait_ms.

Compatibility

  • Code that does not call WithDBTimeout (including code generated by older sqlc) behaves exactly as before. Existing metrics keep their meaning; wpgx_latency_milliseconds still includes the wait.
  • The caller's context deadline and cancellation always apply. Transact is unchanged.
  • Rows already received before the timeout expires can still be read; the expiry is counted in wpgx_timeout_total.

Known limitations

  • Behind PgBouncer (transaction pooling), time queued inside PgBouncer counts as database time.
  • A client-side timeout does not cancel the statement on the server.

Docs: README "Database timeouts"; design record docs/changelogs/2026-11-20-db-timeout-after-acquire.md.

Full Changelog: v0.5.1...v0.6.0