-
Notifications
You must be signed in to change notification settings - Fork 155
Description
Bug: Voucher Redemption Race Condition
Describe the bug
The voucher redemption system has a critical race condition that allows multiple concurrent requests to exceed the max_usages limit. When multiple users attempt to redeem the same voucher simultaneously, the validation check occurs before acquiring the database lock, creating a window where all concurrent requests can pass validation and successfully redeem the voucher beyond its intended limit.
In our testing, a voucher with max_usages=3 was successfully redeemed 5 times (167% over limit).
Root Cause
The bug is located in app/eventyay/base/services/cart.py:
- Lines 1002-1021 (
_get_voucher_availability): Voucher availability validation happens without any lock - Lines 1358-1368 (
_require_locking): Database lock is acquired after validation has already completed
Expected behavior
A voucher with max_usages=3 should only allow exactly 3 redemptions. The 4th and 5th concurrent requests should fail with an error message indicating the voucher has reached its maximum usage limit.
Screenshots
Screenshot 1: Vouchers Page - Over-redemption Visible
Screenshot 2: Orders Page - Multiple Orders with Same Voucher

Metadata
Metadata
Assignees
Labels
Type
Projects
Status