Skip to content
Race condition Write-up Intermediate

Bypassing a Coupon’s `usage_limit` via a Race Condition in an E-Commerce Platform

A Rails e-commerce platform checked a coupon's redemption limit by counting only already-committed completed orders, under PostgreSQL's default READ COMMITTED isolation, with no lock on the coupon row. A normal customer could complete several orders with the same single-use coupon at the same instant, so each check saw zero prior redemptions and all orders committed, redeeming the coupon past its limit.

Zyadatef Follow

Published on medium.com

Cybersecurity

Zyadatef, on medium.com

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 6 min read.

Context

A Ruby on Rails e-commerce platform lets customers apply promotion codes at checkout. Each promotion can carry a redemption cap: a single-use coupon, a code for the first N customers, a one-time free-shipping or free-product code. The platform is supposed to guarantee that cap regardless of how orders are timed.

The enforcement is application-level. When a customer applies a coupon, the platform counts the completed orders that already used the code and compares that count with the configured limit. The check is wired to before_transition to: :complete, so it runs before an order moves into the complete state.

The defect is a TOCTOU (Time-of-Check to Time-of-Use) race condition: the count and the completion are not serialised at the coupon level, so several orders sharing one code can all pass the check before any of them commits. No elevated privileges are needed; any normal customer who can place and complete orders can exploit it.

Setup

The report describes a live install of the platform. The researcher created a promotion with a coupon code and usage_limit = 1, then prepared several orders, each with an eligible line item, all carrying the same coupon.

Two scripts were written to prove the issue:

  • Sequential baseline: completes two orders with the same coupon one after the other, to confirm the guard works in the normal case.
  • Concurrent race (the exploit): prepares 4 orders with the same coupon and uses 4 threads on separate DB connections, all held on a barrier that releases at the same instant, so they enter the completion path (Order#complete!) simultaneously. Repeated over 5 rounds.

A script is necessary here because the completions must run at the same instant to hit the concurrency window, which is hard to do by hand.

Finding it

The researcher looked at how the usage limit is enforced. The simplified logic is:

def usage_limit_exceeded?
  usage_limit.present? && usage_count >= usage_limit
end
# Counts completed orders that used the coupon
def usage_count
  # COUNT over orders whose state is 'complete' and that are tied to the coupon
  adjustments_for_this_promotion.where(orders: { state: 'complete' }).count
end

The intent is simple: count the orders that have actually finished using this code, and block the coupon once the count reaches the limit. The check runs before the transition to complete.

Three facts combine to open a window:

  1. usage_count only sees committed orders. An order that is still mid-transaction and has not committed yet is not counted.
  2. The default isolation level is READ COMMITTED. Under this level, each transaction only sees data that was committed at the time of each statement. Two orders running at the same instant do not see each other until one of them commits.
  3. The only lock in the path is per-order. There is a mutex ensuring the same order is not completed twice simultaneously (a unique row on order_id), but it does not serialise different orders that share the same coupon. There is no SELECT … FOR UPDATE on the promotion or coupon row.

So the check and the completion have a window between them, and that window is not serialised at the coupon level.

Exploitation

Step 1: create the promotion

Create a promotion with a coupon code and usage_limit = 1.

Step 2: prepare several orders with the same coupon

As a normal customer, prepare several orders (say 4), each with an eligible line item, and apply the same coupon to all of them. They all apply successfully, because no completed order has used the code yet (usage_count = 0).

Step 3: advance to the final checkout step

Advance all orders to the final checkout step, ready to complete.

Step 4: complete all orders at the same instant

Fire the completion request for all four orders in parallel. The timeline looks like this:

Time
Order 1:  [check: usage_count=0 OK] ............... [complete / COMMIT]
Order 2:  [check: usage_count=0 OK] ............ [complete / COMMIT]
Order 3:  [check: usage_count=0 OK] ........ [complete / COMMIT]
Order 4:  [check: usage_count=0 OK] .... [complete / COMMIT]
                     ^
         Every order ran its check BEFORE any of them committed,
         so they all saw "zero redemptions" and all proceeded.
Result: usage_count = 4   (the limit was 1)

All four orders run the usage_count check at roughly the same instant. Because none of them has committed yet, the count returns zero for all of them. They all pass the check, all complete, and all commit.

Step 5: observe the result

All orders reach the complete state with the discount applied, and usage_count == 4 despite usage_limit == 1.

Concurrency is the precondition. Run the same steps sequentially and the second order is rejected with "Coupon code usage limit exceeded", which confirms the defect is the concurrency window, not a missing check.

Control run (sequential)

The guard works correctly when orders are completed one after the other:

Promotion #1 code=SEQ3663 usage_limit=1 rules=0
Order A #R859454303 coupon_applied_success=true  promo_total=-5.0 total=105.0
usage_count after A = 1
Order B #R545183085 coupon_applied_success=false error="Coupon code usage limit exceeded"
FINAL usage_count = 1  (limit=1)
BASELINE_OK: guard holds sequentially

Order A applies the coupon and brings the count to 1. Order B is refused with the usage-limit error, and the final count stays at 1.

Exploit run (concurrent)

round 0: coupon_applied=4/4  orders_completed=4  usage_count=4 (limit 1)  XXXX BYPASS
round 1: coupon_applied=4/4  orders_completed=4  usage_count=4 (limit 1)  XXXX BYPASS
round 2: coupon_applied=4/4  orders_completed=4  usage_count=4 (limit 1)  XXXX BYPASS
round 3: coupon_applied=4/4  orders_completed=4  usage_count=4 (limit 1)  XXXX BYPASS
round 4: coupon_applied=4/4  orders_completed=4  usage_count=4 (limit 1)  XXXX BYPASS
==============================
MAX usage_count observed = 4 (usage_limit was 1)
RESULT: RACE CONFIRMED — coupon redeemed past its usage_limit

The result is reproducible 5 out of 5 rounds: usage_count = 4 every round against a limit of 1.

From the original on medium.com

Root cause

The difference between correct and faulty behaviour is concurrency, not a missing check. The check exists and works correctly in the sequential case, but it collapses under concurrent execution.

Three points in the code form the vulnerability:

  • legacy_promotions/.../promotion.rb → usage_limit_exceeded? / usage_count: counts only committed (complete) orders, so concurrent in-flight orders are invisible to it.
  • Eligibility re-check wired to before_transition to: :complete: the check runs inside each transaction independently, with no serialisation against other orders.
  • The order mutex (unique row on order_id): locks the order, not the coupon. Different orders using the same code never contend. There is no SELECT … FOR UPDATE on the coupon row.

The engineering takeaway: an application-level COUNT under READ COMMITTED cannot enforce an invariant like "this coupon is used only once". That invariant must be enforced at the database level.

Impact

Any redemption-limited promotion can be defeated:

  • Single-use codes.
  • "First N customers" codes.
  • One-time free-shipping, free-product or percentage-off codes.

An attacker with only normal customer checkout ability turns a bounded discount into an unbounded one, causing direct financial loss: free or deeply discounted goods, drained promotional budgets, resale of abused codes. No elevated privilege is required.

The same counting pattern also governs per-code usage limits (per_code_usage_limit), so those are expected to be bypassable by the same method.

Fix

The report does not describe a fix that was applied. Its stated conclusion is that the invariant must be enforced at the database level rather than by an application-level COUNT under READ COMMITTED.

Variants to test

  • Other redemption caps on the same platform. Apply the same parallel-completion approach to "first N customers" codes and per-code limits (per_code_usage_limit). A positive result is a final count above the configured limit after a concurrent run, with every order in the complete state.
  • Other application-level COUNT guards. Look for any limit enforced by counting committed rows before a state transition. A positive result is the same pattern: a sequential run refuses the second attempt, a concurrent run lets several through.
  • Higher isolation levels. Repeat the race against a target using REPEATABLE READ or SERIALIZABLE.
  • Lock scope checks. Where a per-object mutex exists (here a unique row on order_id), test whether two different objects sharing the same limited resource contend at all. A positive result is several distinct objects passing the check simultaneously.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 17 min read.

What happened, in plain words

An online shop built with a tool called Ruby on Rails lets customers type in a discount code at checkout. Some of those codes are meant to be used only a limited number of times: a single-use coupon, a code for the first 100 customers, a one-time free-shipping code. The shop is supposed to make sure that limit holds no matter how customers time their orders.

The way the shop enforces the limit is simple: when someone applies a code, the shop counts how many finished orders have already used it, and compares that count with the limit. If the count has reached the limit, the code is refused.

The flaw is a timing problem. The count and the finishing of the order are two separate steps, and nothing stops several orders that share the same code from all doing the count at the same moment. Each one sees zero previous uses, each one passes, and each one finishes. A coupon meant for one use gets used four times. This kind of bug is called a race condition, and more precisely a TOCTOU (Time-of-Check to Time-of-Use) race condition.

No special access is needed. Any normal customer who can place and complete orders can do it. The researcher confirmed it on a live install: usage_count = 4 against usage_limit = 1, reproduced 5 out of 5 runs.

Introduction

On most e-commerce platforms, coupons come with a usage cap: a code for the first 100 customers, one use per account, a one-time free-shipping code, and so on. Logically, the platform must guarantee that cap holds no matter how the orders are timed.

The problem here is that the platform enforces that cap with an application-level COUNT, and that count is not protected against concurrent execution. The result is a TOCTOU (Time-of-Check to Time-of-Use) race condition that turns a limited coupon into an effectively unlimited one.

No elevated privileges are required: any normal customer who can place and complete orders can exploit it.

A quick word on the terms, since they come up constantly. An application is the shop's own code, the part written by the shop's developers, as opposed to the database, the separate program that stores the data. A COUNT is a database instruction that asks "how many rows match this condition?" A race condition is what happens when two things run at the same time and the result depends on which one gets there first. TOCTOU means the gap between the moment something is checked and the moment it is used: if the world can change in that gap, the check can be wrong by the time it matters.

Background: how the usage limit is enforced

When a customer applies a coupon, the platform checks whether the coupon has exceeded its limit. Simplified logic:

def usage_limit_exceeded?
  usage_limit.present? && usage_count >= usage_limit
end

This is Ruby, the language the shop is written in. Line by line:

  • def usage_limit_exceeded? starts the definition of a yes/no question the shop can ask: "has this coupon gone over its limit?" The question mark at the end is a Ruby convention for methods that return true or false.
  • usage_limit.present? asks whether a limit is set at all. If a coupon has no limit, there is nothing to exceed.
  • && means "and": both sides must be true.
  • usage_count >= usage_limit compares the number of times the coupon has been used with the allowed number. >= means "greater than or equal to".
  • end closes the definition.

So the shop refuses the coupon when a limit exists and the number of uses has reached it. The interesting part is how usage_count is calculated:

# Counts completed orders that used the coupon
def usage_count
  # COUNT over orders whose state is 'complete' and that are tied to the coupon
  adjustments_for_this_promotion.where(orders: { state: 'complete' }).count
end

Line by line:

  • The first line starting with # is a comment, a note for humans that the computer ignores. It says this method counts completed orders that used the coupon.
  • def usage_count starts the definition of the counting method.
  • The second comment explains what the next line does.
  • adjustments_for_this_promotion means "the discount records attached to this promotion". A promotion is the shop's internal name for a coupon or discount campaign.
  • .where(orders: { state: 'complete' }) narrows those records down to the ones whose order is in the complete state, meaning the order has finished.
  • .count asks the database to count how many rows are left.
  • end closes the method.

The intent is simple: "count the orders that have actually finished using this code; if the count reached the limit, block it."

This check runs before the transition to the complete state (wired to before_transition to: :complete). In plain words, the shop has a rule that says "just before an order becomes complete, run this check".

Where's the flaw?

Three facts combine to open the window:

  1. usage_count only sees committed orders. An order that is still mid-transaction and hasn't committed yet is not counted.
  2. The default isolation level is READ COMMITTED. Under this level, each transaction only sees data that was committed at the time of each statement. Two orders running at the same instant don't see each other until one of them commits.
  3. The only lock in the path is per-order. There is a mutex ensuring the same order isn't completed twice simultaneously (a unique row on order_id), but it does not serialise different orders that share the same coupon. There is no SELECT … FOR UPDATE on the promotion / coupon row.

These three need unpacking, because they are the heart of the bug.

A transaction is a group of database changes that are treated as one unit: either all of them happen, or none do. Think of a bank transfer: taking money from one account and adding it to another must both happen, or neither. Until a transaction is committed (finalised), its changes are not visible to anyone else. It is like writing in pencil and only inking it at the end: other people reading the page do not see your pencil marks.

An isolation level is a setting that decides how much one transaction can see of other transactions running at the same time. READ COMMITTED, the default in PostgreSQL (the database used here), is the most permissive common setting: each statement inside a transaction sees only data that was committed before that statement ran. Two transactions running at the same moment do not see each other's unfinished work.

A lock is a way to make one transaction wait for another. A mutex (short for mutual exclusion) is a lock that lets only one thing at a time through. Here the shop has a mutex on each order, so the same order cannot be completed twice at once. But that lock is keyed to the order, not to the coupon. Two different orders using the same coupon never wait for each other.

SELECT … FOR UPDATE is a database instruction that reads a row and locks it until the transaction ends, so nobody else can change it in the meantime. The report says there is no such lock on the promotion or coupon row.

So the "has the coupon exceeded its limit?" check and the "complete the order" step have a window between them, and that window is not serialised at the coupon level. Serialised means forced to happen one after another, never at the same time.

Root cause: TOCTOU

The timeline of the attack (4 orders with the same coupon, all completing at once):

Time
Order 1:  [check: usage_count=0 OK] ............... [complete / COMMIT]
Order 2:  [check: usage_count=0 OK] ............ [complete / COMMIT]
Order 3:  [check: usage_count=0 OK] ........ [complete / COMMIT]
Order 4:  [check: usage_count=0 OK] .... [complete / COMMIT]
                     ^
         Every order ran its check BEFORE any of them committed,
         so they all saw "zero redemptions" and all proceeded.
Result: usage_count = 4   (the limit was 1)

This is a picture of time flowing left to right. Each line is one order. The square brackets on the left are the moment the order asks "how many times has this coupon been used?" and gets the answer zero, which is fine, so it continues. The dots are the rest of the work. The brackets on the right are the moment the order is completed and its changes are committed to the database.

The caret and the note underneath explain the key point: every order ran its check before any of them committed. Because none of the four had committed when the others asked, all four got the answer zero. All four passed. All four completed. The final count is 4 even though the limit was 1.

All four orders run the usage_count check at roughly the same instant. Because none of them has committed yet, the count returns zero for all of them. So they all pass the check, all complete, and all commit. In the end, the coupon with a limit of 1 was redeemed 4 times.

The difference between correct and faulty behaviour here is concurrency, not a missing check: the check exists and works correctly in the sequential case, but it collapses under concurrent execution. Sequential means one after another; concurrent means at the same time.

The affected code

The three points that form the vulnerability:

  • legacy_promotions/.../promotion.rb → usage_limit_exceeded? / usage_count : counts only committed (complete) orders, so concurrent in-flight orders are invisible to it.
  • Eligibility re-check wired to before_transition to: :complete : the check runs inside each transaction independently, with no serialisation against other orders.
  • The order mutex (unique row on order_id ): locks the order, not the coupon. Different orders using the same code never contend. No SELECT … FOR UPDATE on the coupon row.

The first bullet names a file, legacy_promotions/.../promotion.rb, and the two methods inside it. The path is shortened with ... in the report. In-flight means an order that has started but not yet finished, like a plane that has taken off but not landed. The count cannot see those orders, so it undercounts.

The second bullet says the check is attached to the moment an order becomes complete, and each order runs that check inside its own transaction, with nothing making it wait for other orders.

The third bullet says the only lock is on the order itself, identified by order_id. Two different orders have two different order_id values, so they never wait for each other, even when they share the same coupon. Contend means compete for the same lock; if two things never contend, neither ever waits.

The engineering takeaway: an application-level COUNT under READ COMMITTED cannot enforce an invariant like "this coupon is used only once." That invariant must be enforced at the database level. An invariant is a rule that must always be true, no matter what. If the rule must always hold, the place to enforce it is the database, which is the one component all the orders share, not the application code, which runs separately for each order.

Exploitation scenario (high level)

The whole idea is to make the orders complete at the same instant, before any of them commits:

  1. Create a promotion with a coupon code and usage_limit = 1.
  2. As a normal customer, prepare several orders (say 4), each with an eligible line item, and apply the same coupon to all of them. They all apply successfully, because no completed order has used the code yet (usage_count = 0).
  3. Advance all orders to the final checkout step (ready to complete).
  4. Complete all orders at the same instant: fire the completion request for all four in parallel.
  5. All orders reach the complete state with the discount applied, and usage_count == 4 despite usage_limit == 1.

Why each step matters:

  1. The promotion is the thing being tested. Setting usage_limit = 1 makes the rule easy to check: anything above one use is a bypass.
  2. Several orders are needed because the bug only appears when more than one order races. Each order needs an eligible line item, meaning a product the coupon applies to, otherwise the coupon would be refused for an unrelated reason. All four applications succeed because at that point no order has completed, so the count is still zero.
  3. The orders are moved to the last step before completion, so the only thing left to do is the completion itself. This keeps the timing tight.
  4. The completion requests are sent in parallel, meaning at the same time rather than one after another. This is the step that hits the window.
  5. The result is checked: all four orders are complete with the discount, and the count is 4 against a limit of 1.

Key point: concurrency is the precondition for the exploit. If you run the same steps sequentially, the second order is rejected with "Coupon code usage limit exceeded", which is exactly what confirms the defect is the concurrency window, not a missing check.

Proof of Concept and results

Two scripts were written to prove the issue:

  • Sequential baseline: completes two orders with the same coupon sequentially, to confirm the guard works correctly in the normal case.
  • Concurrent race (the exploit): prepares 4 orders with the same coupon and uses 4 threads on separate DB connections, all held on a barrier that releases at the same instant, so they enter the completion path (Order#complete!) simultaneously. Repeated over 5 rounds.

A script is a small program that automates steps a person would otherwise do by hand. A baseline is a control run: the normal, expected case, used as a comparison. A thread is one line of execution inside a program; several threads can run at the same time. A DB connection is a separate channel to the database; giving each thread its own connection means the database treats them as separate clients, which is what a real set of customers would look like. A barrier is a meeting point in code: every thread waits there until all of them have arrived, then they all continue at once. Order#complete! is the name of the completion method in the shop's code.

A script is necessary here because the completions must run at the same instant to hit the concurrency window, which is hard to do by hand.

Results

Control (sequential): the guard works correctly:

Promotion #1 code=SEQ3663 usage_limit=1 rules=0
Order A #R859454303 coupon_applied_success=true  promo_total=-5.0 total=105.0
usage_count after A = 1
Order B #R545183085 coupon_applied_success=false error="Coupon code usage limit exceeded"
FINAL usage_count = 1  (limit=1)
BASELINE_OK: guard holds sequentially

Line by line:

  • Promotion #1 code=SEQ3663 usage_limit=1 rules=0 says the promotion being tested is number 1, its code is SEQ3663, its limit is 1, and it has no extra rules attached.
  • Order A #R859454303 coupon_applied_success=true promo_total=-5.0 total=105.0 says order A, with reference R859454303, accepted the coupon (true means yes), the discount was 5.0 off (shown as -5.0), and the order total came to 105.0.
  • usage_count after A = 1 says that after order A, the coupon has been used once.
  • Order B #R545183085 coupon_applied_success=false error="Coupon code usage limit exceeded" says order B, reference R545183085, was refused, and the error message was "Coupon code usage limit exceeded".
  • FINAL usage_count = 1 (limit=1) says the final count is 1, which matches the limit.
  • BASELINE_OK: guard holds sequentially is the script's own verdict: the guard works when orders are done one after another.

Exploit (concurrent): limit bypassed:

round 0: coupon_applied=4/4  orders_completed=4  usage_count=4 (limit 1)  XXXX BYPASS
round 1: coupon_applied=4/4  orders_completed=4  usage_count=4 (limit 1)  XXXX BYPASS
round 2: coupon_applied=4/4  orders_completed=4  usage_count=4 (limit 1)  XXXX BYPASS
round 3: coupon_applied=4/4  orders_completed=4  usage_count=4 (limit 1)  XXXX BYPASS
round 4: coupon_applied=4/4  orders_completed=4  usage_count=4 (limit 1)  XXXX BYPASS
==============================
MAX usage_count observed = 4 (usage_limit was 1)
RESULT: RACE CONFIRMED — coupon redeemed past its usage_limit

Line by line:

  • Each round line is one attempt. coupon_applied=4/4 means all four orders accepted the coupon. orders_completed=4 means all four finished. usage_count=4 (limit 1) means the coupon was used four times against a limit of one. XXXX BYPASS is the script flagging the bypass.
  • The five rounds are numbered 0 to 4, so the test was repeated five times.
  • MAX usage_count observed = 4 (usage_limit was 1) is the highest count seen across all rounds.
  • RESULT: RACE CONFIRMED — coupon redeemed past its usage_limit is the script's verdict: the race worked and the coupon was used beyond its limit.

The result is reproducible 5 out of 5 rounds: usage_count = 4 every round against a limit of 1. Reproducible means it works every time it is tried, not just once by luck.

(Insert the attached terminal screenshot here.)

From the original on medium.com

Impact

Any redemption-limited promotion can be defeated:

  • Single-use codes.
  • "First N customers" codes.
  • One-time free-shipping / free-product / percentage-off codes.

An attacker with only normal customer checkout ability turns a bounded discount into an unbounded one, causing direct financial loss (free or deeply discounted goods, drained promotional budgets, resale of abused codes). No elevated privilege is required.

Impact means the real-world harm a bug can cause. Bounded means limited; unbounded means without limit. Promotional budgets are the money a shop sets aside for discounts. Resale of abused codes means taking the cheaply bought goods or the codes themselves and selling them on.

The same counting pattern also governs per-code usage limits (per_code_usage_limit), so those are expected to be bypassable by the same method. A per-code usage limit is a cap on how many times one specific code can be used, as opposed to a cap on the whole promotion.

Fix

The report does not describe a fix that was applied. Its stated conclusion is that the invariant must be enforced at the database level rather than by an application-level COUNT under READ COMMITTED.

In plain words: make the database itself refuse the second use, or make the second order wait until the first has finished. A database constraint is a rule the database enforces on its own, such as "this value must be unique". An atomic counter is a counter that can be increased by only one transaction at a time, so two increases can never both read the same old value.

Variants to test

  • Other redemption caps on the same platform. Apply the same parallel-completion approach to "first N customers" codes and per-code limits (per_code_usage_limit). A positive result is a final count above the configured limit after a concurrent run, with every order in the complete state.
  • Other application-level COUNT guards. Look for any limit enforced by counting committed rows before a state transition. A positive result is the same pattern: a sequential run refuses the second attempt, a concurrent run lets several through.
  • Higher isolation levels. Repeat the race against a target using REPEATABLE READ or SERIALIZABLE.
  • Lock scope checks. Where a per-object mutex exists (here a unique row on order_id), test whether two different objects sharing the same limited resource contend at all. A positive result is several distinct objects passing the check simultaneously.

A variant is a related version of the same bug. Referral credits are rewards given for bringing in new customers. Gift-card balances are the amounts stored on gift cards. Stock reservations are holds placed on inventory while a customer checks out. REPEATABLE READ and SERIALIZABLE are stricter isolation levels than READ COMMITTED: they make transactions see a more stable view of the data, or behave as if they ran one after another. Lock scope means what a lock covers: one order, one coupon, or the whole table.

Glossary

  • Application: the shop's own code, written by its developers, as opposed to the database.
  • Application-level check: a rule enforced in the shop's code rather than by the database.
  • Atomic counter: a counter that only one transaction can change at a time, so two changes cannot both read the same old value.
  • Barrier: a meeting point in a program where several threads wait until all have arrived, then continue together.
  • Baseline: a control run of the normal, expected case, used for comparison.
  • Bounded: limited to a maximum.
  • Commit: to finalise a transaction so its changes become visible to others.
  • Concurrency: several things happening at the same time.
  • Concurrent: happening at the same time.
  • Contend: to compete for the same lock; if two things never contend, neither waits.
  • Coupon: a code that gives a discount at checkout.
  • Database: the separate program that stores the shop's data.
  • Database constraint: a rule the database enforces itself, such as a value that must be unique.
  • DB connection: a separate channel from a program to the database.
  • Eligible line item: a product in an order that the coupon applies to.
  • In-flight: started but not yet finished.
  • Invariant: a rule that must always be true.
  • Isolation level: a database setting that decides how much one transaction can see of others running at the same time.
  • Lock: a mechanism that makes one transaction wait for another.
  • Mutex: short for mutual exclusion; a lock that lets only one thing through at a time.
  • Per-code usage limit: a cap on how many times one specific code can be used.
  • Promotion: the shop's internal name for a coupon or discount campaign.
  • Promotional budget: the money a shop sets aside for discounts.
  • Race condition: a bug where the result depends on which of two simultaneous actions gets there first.
  • READ COMMITTED: the default PostgreSQL isolation level, where each statement sees only data committed before it ran.
  • Reproducible: works every time it is tried, not just once by luck.
  • REPEATABLE READ: a stricter isolation level than READ COMMITTED, giving a more stable view of the data.
  • Script: a small program that automates steps a person would otherwise do by hand.
  • SELECT … FOR UPDATE: a database instruction that reads a row and locks it until the transaction ends.
  • Sequential: one after another.
  • Serialised: forced to happen one after another, never at the same time.
  • SERIALIZABLE: the strictest isolation level, making transactions behave as if they ran one after another.
  • Thread: one line of execution inside a program; several can run at the same time.
  • TOCTOU: Time-of-Check to Time-of-Use; a bug where the world can change between a check and the action that relies on it.
  • Transaction: a group of database changes treated as one unit, all or nothing.
  • Unbounded: without limit.
  • Variant: a related version of the same bug.

Similar reports

View all

Same bug class and techniques, clearest first.

Race conditions

The lesson behind this report.

Parallel requests reach a state the code assumed could not happen: a coupon used twice, a limit overrun, a check skipped.