Skip to content

fix(mail): prevent concurrent setup runs - #80

Merged
Hydralerne merged 1 commit into
oblien:mainfrom
Rajioba1:fix/mail-setup-concurrency
Jul 22, 2026
Merged

fix(mail): prevent concurrent setup runs#80
Hydralerne merged 1 commit into
oblien:mainfrom
Rajioba1:fix/mail-setup-concurrency

Conversation

@Rajioba1

Copy link
Copy Markdown
Contributor

Summary

  • reserve the process-local setup slot before the first database await
  • add a non-blocking Postgres advisory-lock handle for cross-replica coordination
  • hold the advisory lock for the complete SSE setup lifecycle
  • release the lock on completion, pause, failure, disconnect, and setup-start errors
  • return 409 immediately when another replica owns the server lock
  • return 503 instead of running unlocked when reservation persistence fails

Why

The previous active check and assignment were separated by an awaited database lookup, so two requests could both pass the check. The mail_servers fallback was also not an atomic lock because upsert() updates on conflict.

The former one-hour row heuristic also blocked intentional DNS/PTR resumes and could expire while a valid long-running install was still active. A session-level advisory lock follows the actual SSE lifecycle instead of relying on elapsed time.

Tests

  • focused mail suite: 24 passed
  • advisory-lock tests: 4 passed
  • bun run --cwd apps/api lint
  • bun run --cwd packages/db lint
  • Prettier check on all new and directly formatted files
  • independent code review: green, no remaining blockers

bun format was run per CONTRIBUTING.md. Its repository-wide Windows line-ending churn and unrelated formatting changes were excluded; the pre-existing mail.controller.ts file is not fully Prettier-clean on main.

Fixes #79

@Hydralerne
Hydralerne merged commit 48ba713 into oblien:main Jul 22, 2026
1 check 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.

bug: concurrent mail setup requests can start duplicate installers

2 participants