Skip to content

fix(deploy): write max_connections after the database and firewall - #272

Merged
CalvinAllen merged 2 commits into
mainfrom
fix/deploy/postgres-write-order
Nov 13, 2026
Merged

CalvinAllen merged 2 commits into
mainfrom
fix/deploy/postgres-write-order

Conversation

@CalvinAllen

Copy link
Copy Markdown
Member

Summary

#271's deploy failed at provision-postgres with ServerIsBusy, before the migrations or the web app, so the site kept running #269. The busy operation was the deploy's own.

The generated Bicep writes three children of the Postgres server with nothing but parent: postgres: the csadvent database, the AllowAllAzureIps firewall rule, and the max_connections setting from AppHost.cs. ARM writes them all at once, and a flexible server refuses to change a setting while another operation is running. The activity log shows the race on every recent deploy:

Deploy Database write done max_connections write
#267, Nov 12 21:08:22.190 21:08:22.210, succeeded
#269, Nov 13 00:10:22.204 00:10:22.316, succeeded
#271, Nov 13 13:57:59.455 13:57:59.282, failed

The live setting is already 429 with nothing waiting on a restart. The write only failed because of when it happened.

Changes

  • PostgresWrites.AfterTheOtherChildren makes a server setting depend on the server's databases and firewall rules. max_connections uses it, so the generated Bicep now has:

    resource maxConnections 'Microsoft.DBforPostgreSQL/flexibleServers/configurations@2024-08-01' = {
      ...
      parent: postgres
      dependsOn: [
        postgreSqlFirewallRule_AllowAllAzureIps
        csadvent
      ]
    }

    A deploy waits for the firewall rule, about 50 seconds, before writing the setting.

  • PostgresWritesTests compiles a server with a database, a firewall rule and a setting, and checks the setting's dependsOn. Like MigrateFirstTests, it needs no AppHost or Docker.

  • The runbook has a new A Deploy That Failed in Azure section: what a failed provision-… step means, and that ServerIsBusy is fixed by running the Deploy workflow again.

Merging this deploys #271 too.

Also: #271's time-limit tests run on their own

APageThatTakesTooLongToReadIsLeftForAPerson failed once in a full local run. It passed when run alone. The limit is a CancelAfter timer, and its callback needs a free thread-pool thread. A benchmark showed AngleSharp checks the token during the parse (a direct cancel at 50 ms was noticed at 105 ms), and that the 1 ms limit fired 20 times out of 20 with the pool idle. With the pool saturated it fired 0 times out of 10, and the parse ran to the end.

  • The two tests that need the limit to fire mid-parse move to ReadTimeLimitTests, in a new NonParallel collection (DisableParallelization), which runs after the parallel tests.
  • CLAUDE.md's Testing section says when to use it.
  • Production isn't affected in practice: a starved pool adds threads, so the 10-second limit can only fire late, not never.

Testing

  • aspire do publish-azure-environment in the PublishCheck environment, then az bicep build on main.bicep: it generates the dependsOn above and compiles.
  • dotnet build: 0 warnings, 0 errors.
  • dotnet test (SDK 11.0.100, Docker): all 1,159 unit tests and 348 integration tests pass. The unit suite also passed three full runs in a row with the timing tests in NonParallel.

@CalvinAllen CalvinAllen changed the title fix(deploy): write the database server's setting after its other children fix(deploy): write max_connections after the database and firewall Nov 13, 2026
The deploy wrote the Postgres server's database, firewall rule and
max_connections setting at once, and the server refuses a setting while
another operation runs, so a deploy could fail with ServerIsBusy. The
setting now depends on the database and firewall rule. The runbook says
what a deploy that fails in Azure means.
The limit's timer needs a free thread-pool thread to fire during the
parse, which the parallel tests could take, so the two tests that rely
on it run in a NonParallel collection after the others.
@CalvinAllen
CalvinAllen force-pushed the fix/deploy/postgres-write-order branch from b3c4631 to 0267abd Compare November 13, 2026 17:07
@CalvinAllen
CalvinAllen merged commit 0d8fbe6 into main Nov 13, 2026
3 checks passed
@CalvinAllen
CalvinAllen deleted the fix/deploy/postgres-write-order branch November 13, 2026 17:21
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