Skip to content

[M2.2c4c1-fix] Bound concurrent replay transactions below the connection pool - #95

Merged
samuelmbabhazi merged 1 commit into
mainfrom
fix/m2.2-bound-replay-transactions
Nov 5, 2026
Merged

samuelmbabhazi merged 1 commit into
mainfrom
fix/m2.2-bound-replay-transactions

Conversation

@samuelmbabhazi

Copy link
Copy Markdown
Collaborator

Task

Review follow-up for #50 and #51 (M2.2c4c1 and M2.2c4c2). Refs #21

What changed

  • New BoundedConcurrency helper: at most N operations run at once, up to M more wait without holding anything, and callers beyond that get 503 immediately.
  • PrivateIdentityReplay.execute runs its transaction through a limit of 3 active and 32 queued.

Why

With an Idempotency-Key, register, login and reset run inside the replay transaction, which holds a pooled connection while the request waits for Argon2id (PasswordHasher allows 2 running and 16 waiting). An anonymous client sending about 20 concurrent keyed logins could hold up to 18 connections, while the pg pool behind PrismaPg defaults to 10. Every other request, including session checks, then waited for a connection and failed with 503: unauthenticated callers could stall the whole API.

Keeping the command, its audit row and the encrypted retry result in one transaction is what makes retries safe, so the transaction stays. Instead, at most three replay transactions may hold connections, leaving at least seven for everything else. Waiting replays hold no connection.

How it was tested

  • Unit tests for BoundedConcurrency: peak concurrency never exceeds the limit, queued work runs when a slot frees, a full queue fails fast with 503, and failures release their slot.
  • nx run-many -t lint typecheck test -p api in a clean worktree: all pass.
  • Integration tests could not run locally (no Docker in the sandbox) and GitHub Actions is blocked by the account spending limit. CI must pass before merge.

Security considerations

Removes an unauthenticated denial-of-service path. A flood of keyed requests now receives 503 from the replay gate instead of exhausting the database pool. Per-IP and per-subject throttles still apply before this gate.

Checklist

  • Lint, TS tests pass locally
  • Tests added
  • No new shell invocation and no new secret exposure path
  • Audit events unchanged
  • CI green (blocked by billing)

@samuelmbabhazi
samuelmbabhazi force-pushed the fix/m2.2-bound-replay-transactions branch from aa6fabe to 64c837f Compare November 5, 2026 13:52
@samuelmbabhazi
samuelmbabhazi merged commit a5c5f41 into main Nov 5, 2026
2 of 11 checks passed
@samuelmbabhazi
samuelmbabhazi deleted the fix/m2.2-bound-replay-transactions branch November 5, 2026 13:53
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