Skip to content

fix: add distributed lock to dedicated server assignment#139

Merged
lukepolo merged 2 commits intomainfrom
audit/373-server-locking
Apr 9, 2026
Merged

fix: add distributed lock to dedicated server assignment#139
lukepolo merged 2 commits intomainfrom
audit/373-server-locking

Conversation

@Flegma
Copy link
Copy Markdown
Contributor

@Flegma Flegma commented Apr 8, 2026

Summary

  • Wraps the assignDedicatedServer() method's query-assign-reserve flow in a cache.lock() call to prevent race conditions where two matches could claim the same dedicated server
  • Uses a region-scoped lock key (assign-dedicated-server:{region}) since servers are region-specific, matching the existing pattern used for on-demand servers
  • The lock uses Redis SETNX with auto-release (60s TTL, 10 retries), ensuring atomic server assignment even across multiple API instances

Closes 5stackgg/5stack-panel#373

Test plan

  • Verify that dedicated server assignment still works correctly for a single match
  • Simulate concurrent match creation in the same region and confirm no duplicate server assignment
  • Verify lock auto-releases after the operation completes (or after TTL if the process crashes)
  • Confirm on-demand server assignment is unaffected

Flegma added 2 commits April 8, 2026 12:44
Lock failures on assignDedicatedServer now log and fall through to
alternative assignment strategies instead of propagating unhandled.
Lock TTL reduced from default 60s to 10s to match on-demand pattern.
@lukepolo lukepolo merged commit 9150e55 into main Apr 9, 2026
1 check passed
@lukepolo lukepolo deleted the audit/373-server-locking branch April 9, 2026 17:36
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.

[API] Add atomic locking to server assignment flow

2 participants