Skip to content

9.16.4

Choose a tag to compare

@jeremydmiller jeremydmiller released this 17 Jul 13:20
c6310dc

What's Changed

Patch release. Contains everything merged since 9.16.3 — all of it addressing #356, reported by @erdtsieck from a 512-database sharded Marten deployment.

Fixes

  • db-apply no longer trails idle connection pools across a many-database walk, and retries a connection refusal instead of failing the job by @jeremydmiller in #357 and #358 — fixes #356

    ApplyCommand already walked its databases sequentially, but each database in a sharded or multi-tenanted store owns its own data source and nothing released a finished database's pool. With a typical 30s Connection Idle Lifetime and 1–2s spent per database, a walk dragged a rolling tail of ~15–30 idle pools behind the single pool it was actually using — for a job whose real need is one connection at a time. A 53300 too_many_connections on top of that ambient pressure then failed the whole command, and with it the deployment step. The reported workaround was to scale the application down so the deploy could get connections, which is exactly backwards.

    Three changes:

    1. Each database's pool is released once its apply completes. db-apply is a one-shot command that owns its data sources — there are no application sessions sharing them — so peak connection usage now stays at roughly the one database being applied, rather than O(period / idle-lifetime).

    2. A transient connection refusal is retried twice with a clamped, jittered exponential backoff (3 attempts total). Migration failures are not retried and still fail immediately.

    3. Per-database progress is reported as (n/total), so a 512-database walk can be watched and its completion estimated.

What counts as a transient refusal

Decided per provider, and deliberately narrow — a missed code just means today's behavior (fail immediately), while a false positive would silently re-run a migration that genuinely failed:

Provider Retried on Notably excluded
PostgreSQL 53300 too_many_connections, 53400, 57P03 cannot_connect_now the rest of class 53 — 53100 disk_full and 53200 out_of_memory won't clear on a retry
SQL Server 17809 too many user connections, and the Azure SQL resource/throttling set (10928/10929/40197/40501/40613/49918–49920) -2 — SqlClient raises it for command timeouts too, so retrying it would silently re-run a slow CREATE INDEX that merely exceeded CommandTimeout; also 10053/10054/233/64 transport drops
MySQL 1040 too many connections, 1203, 1226, unable-to-connect-to-host deadlocks, access denied
Oracle ORA-00020 max processes exceeded, ORA-12516/12518/12520 listener busy ORA-12537/12570 — raised when an established session drops, indistinguishable from a migration interrupted midway
SQLite nothing — no server, so no connection ceiling to hit n/a

API additions

Both are additive; existing implementors and consumers need no changes.

  • IDatabase.ReleaseConnectionPoolAsync(CancellationToken) — releases a database's pooled connections without disposing the database, which stays usable afterward. Added as a defaulted interface method with a no-op default, so it is not a breaking change for IDatabase implementors.

  • Migrator.ReleaseConnectionPoolAsync(DbConnection, CancellationToken) and Migrator.IsTransientConnectionFailure(Exception) — the provider-specific hooks behind the above, both virtual with inert defaults. They hang off Migrator rather than a database class because only PostgreSQL and SQLite have their own IDatabase base class — SQL Server, MySQL and Oracle databases are built on DatabaseBase<T> directly, so this is what lets those consumers get pool release and retry without implementing anything.

  • Weasel.Core.ExceptionChain.Flatten(Exception) — walks inner and aggregated exceptions. The drivers rarely surface a connection failure bare (multi-host data sources aggregate one failure per host), so any IsTransientConnectionFailure implementation needs this to avoid being inert for exactly the case it exists to catch.

DatabaseExtensions.ApplyAllConfiguredChangesWithRetriesAsync(maxAttempts, baseDelayMs, ct) is available if you want the same retry behavior outside the CLI.

Note on pool-release scope

PostgresqlDatabase clears its specific NpgsqlDataSource. The other providers' drivers key their pools by connection string within the process, so releasing there also drops idle connections held elsewhere in the same process for that connection string. Connections in use are never killed — they're discarded when returned — and for one-shot tooling like db-apply this makes no difference. It's worth knowing if you call ReleaseConnectionPoolAsync() yourself from inside a running application.

Merged PRs

  • #357 — feat: bound db-apply's connection usage over many databases (weasel#356)
  • #358 — feat: extend the pool release and retry to SQL Server, MySQL and Oracle (weasel#356)
  • #359 — release: 9.16.4

Full Changelog: 9.16.3...9.16.4