Skip to content

Bug: Voucher Redemption Race Condition #1398

@ArnavBallinCode

Description

@ArnavBallinCode

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:

  1. Lines 1002-1021 (_get_voucher_availability): Voucher availability validation happens without any lock
  2. 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

Image

Screenshot 2: Orders Page - Multiple Orders with Same Voucher

Image

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions