Skip to content

Commit c0deea5

Browse files
fix: race condition in checkout allows overselling (#1359)
1 parent bbd03e0 commit c0deea5

File tree

1 file changed

+4
-10
lines changed

1 file changed

+4
-10
lines changed

app/eventyay/base/services/orders.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1175,15 +1175,9 @@ def _perform_order(
11751175
meta_info=meta_info,
11761176
)
11771177

1178-
lockfn = NoLockManager
1179-
locked = False
1180-
if positions.filter(
1181-
Q(voucher__isnull=False) | Q(expires__lt=now() + timedelta(minutes=2)) | Q(seat__isnull=False)
1182-
).exists():
1183-
# Performance optimization: If no voucher is used and no cart position is dangerously close to its expiry date,
1184-
# creating this order shouldn't be prone to any race conditions and we don't need to lock the event.
1185-
locked = True
1186-
lockfn = event.lock
1178+
# Always lock the event during checkout to prevent race conditions (overselling).
1179+
# We deliberately skip the previous performance optimization here to ensure data integrity.
1180+
lockfn = event.lock
11871181

11881182
with lockfn() as now_dt:
11891183
positions = list(
@@ -1217,7 +1211,7 @@ def _perform_order(
12171211
)
12181212
if free_order_flow:
12191213
try:
1220-
payment.confirm(send_mail=False, lock=not locked)
1214+
payment.confirm(send_mail=False, lock=False)
12211215
except Quota.QuotaExceededException:
12221216
pass
12231217

0 commit comments

Comments
 (0)