Skip to content

fix(coderd): let only one request create the first user (#32417) - #32538

Merged
BobbyHo merged 3 commits into
release/2.34from
backport/32417-to-2.34
Nov 23, 2026
Merged

BobbyHo merged 3 commits into
release/2.34from
backport/32417-to-2.34

Conversation

@coder-backporter-app

@coder-backporter-app coder-backporter-app Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Backport of #32417

Original PR: #32417 — fix(coderd): let only one request create the first user
Merge commit: cf68914
Requested by: @BobbyHo

The automatic cherry-pick had conflicts. They are resolved by hand; the fix is the same as in #32417.

Differences from #32417

The automatic cherry-pick of cf68914 to release/2.34 had conflicts.
Please cherry-pick manually:

    git cherry-pick -x -m1 cf68914
@coder-backporter-app coder-backporter-app Bot added the backport/v2.34 Backport PR targeting release/2.34 label Nov 20, 2026
Prevent multiple Owner accounts from being created during concurrent first-user setup requests.

Refs https://linear.app/codercom/issue/CORE-853

Use a transaction-scoped PostgreSQL advisory lock shared by password setup and GitHub/OIDC first sign-ins. Recheck the user count under the lock to ensure only one account receives the Owner role, while preserving existing responses for subsequent requests.

- Add a stable, backport-safe lock ID and shared first-user setup helper.
- Apply locking only when no users exist, leaving normal sign-ins unaffected.
- Use `READ COMMITTED` isolation to ensure accurate counts regardless of database defaults.
- Keep validation and trial licence requests outside the lock.
- Preserve existing API responses, status codes, and telemetry behavior.

**Testing**
- Add concurrent password, OAuth, and mixed-path tests verifying exactly one Owner.
- Cover lock contention, cancellation, isolation levels, telemetry, and lock bypass.
- Verify tests fail when locking is removed.
- Pass targeted race tests, 124 related tests, lint, and `intxcheck`.

**Known limitation:** A burst of concurrent OAuth sign-ins on an empty deployment could exhaust the database connection pool while waiting for the lock. This remains unverified and is outside the scope of this fix.

**Note:** Stacked on #32324; will be rebased onto `main` after it merges.

(cherry picked from commit cf68914)
@BobbyHo BobbyHo changed the title fix(coderd): let only one request create the first user (#32417) (conflicts) fix(coderd): let only one request create the first user (#32417) Nov 21, 2026
@BobbyHo
BobbyHo requested a review from denisra November 21, 2026 16:58
@BobbyHo
BobbyHo merged commit d59b538 into release/2.34 Nov 23, 2026
35 of 36 checks passed
@BobbyHo
BobbyHo deleted the backport/32417-to-2.34 branch November 23, 2026 17:17

This branch had an error being deployed

1 failed deployment
docs-preview — 7bd18db7 Deployed Nov 23, 2026 by BobbyHo via cleanup #355
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport/v2.34 Backport PR targeting release/2.34

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants