Skip to content

Fix: handle concurrent vote race condition gracefully#26

Merged
ralyodio merged 1 commit into
profullstack:masterfrom
FuturMix:fix/vote-race-condition
Jun 15, 2026
Merged

Fix: handle concurrent vote race condition gracefully#26
ralyodio merged 1 commit into
profullstack:masterfrom
FuturMix:fix/vote-race-condition

Conversation

@FuturMix

Copy link
Copy Markdown
Contributor

Summary

Fixes #25

The vote endpoint's SELECT+INSERT pattern can throw a UNIQUE constraint error on concurrent requests, returning 500 instead of 409.

Changes

  • apps/web/app/api/coupons/vote/route.ts: Use INSERT OR IGNORE to handle concurrent duplicates gracefully; keep SELECT check for normal duplicate feedback

Test plan

  • Single vote: works normally, returns success with updated count
  • Duplicate vote (non-concurrent): returns 409 "already_voted"
  • Concurrent duplicate votes: both return cleanly (no 500 errors)

🤖 Generated with Claude Code

The vote handler uses SELECT to check for duplicates, then INSERT. Two
concurrent requests can both pass the SELECT check. The UNIQUE
constraint on (coupon_id, voter_did) catches this at the DB level, but
the resulting constraint violation error returns a generic 500 instead
of the expected 409 response.

Use INSERT OR IGNORE so concurrent duplicate inserts are silently
ignored instead of throwing errors, while keeping the SELECT check for
user-friendly feedback on normal duplicate attempts.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@ralyodio ralyodio merged commit b93d28c into profullstack:master Jun 15, 2026
5 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.

Bug: Vote endpoint race condition returns 500 on concurrent duplicate votes

2 participants