Skip to content

DRU-856 -- Refuse a create at a provider's host limit - #74

Merged
czpython merged 1 commit into
mainfrom
paulo/dru-856-per-provider-host-limit-refuses-a-create-with-a-capacity-503
Oct 12, 2026
Merged

czpython merged 1 commit into
mainfrom
paulo/dru-856-per-provider-host-limit-refuses-a-create-with-a-capacity-503

Conversation

@czpython

Copy link
Copy Markdown
Owner

HOST_LIMITS sets the most live hosts per provider, as JSON (for example {"exe": 28, "docker": 6}). A provider that it does not name has no limit.

Behavior

  • create_host takes pg_advisory_xact_lock keyed by the provider name, in the transaction that inserts the row. The lock serializes the creates of one provider, so two requests cannot both pass the count.
  • The count includes the provider's hosts that are not in error and have not expired. Provisioning rows count. Warm pool hosts count, because the pool maintainer creates through the same path.
  • At the limit, POST /hosts returns 503 with CAPACITY and Retry-After: 30. The refused create leaves no row.
  • SQLite has no advisory locks, so it runs the count only.

Checks

  • One service test: exe at its limit refuses, stub with no limit creates.
  • uv run pytest passes on SQLite and on Postgres 17 (785 tests).
  • ruff check, ruff format --check, and pyright pass.

HOST_LIMITS sets the most live hosts per provider, as JSON. A provider
it does not name has no limit. A live host is not in error and has not
expired. Warm pool hosts count, because the pool maintainer creates
through the same path.

create_host takes a Postgres advisory lock keyed by the provider name
in the insert transaction, counts the live hosts, and refuses at the
limit. A refused create returns 503 with CAPACITY and Retry-After, and
leaves no row.
@czpython
czpython merged commit ef88f91 into main Oct 12, 2026
6 checks passed
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