Sold Out, Sold Again — JavaScript Bug Hunt
Inspired by every on-sale meltdown where more tickets sell than exist.
- Language: JavaScript
- Layer: Database
- Difficulty: Medium
- Concepts: Inventory, Check-Then-Act
- Modelled on: Ticketmaster-class sales
- Visible tests: the second oversized request is rejected; requests that fit all pass
- Reward: 50 XP for a complete fix
Incident
- Severity: SEV-1 (priority: Critical (refund storm))
- Ticket: BUG-OVERSELL
- Reported by: ticketing
- Time to fix: 20 minutes, the target for a medium incident
Failing checks on the shipped build
- the second oversized request is rejected — only 2 seats remained: expected [true,false] but got [true,true]
- requests that fit all pass — expected 0 but got 7
How to work this incident
- Read the report: write down the expected behaviour and the actual one in a sentence each.
- Reproduce it: run the visible tests and find the failing check that matches the report.
- Read the logs and the failing checks for the first value that is wrong — the earliest wrong value is nearer the cause than the loudest error.
- Follow the data through the query or the repository code; compare the rows it returns with the rows the report expects.
- Fix the cause rather than the symptom, run the visible tests again, and submit against the hidden ones — then write the root cause down.
Briefing
Inspired by every on-sale meltdown where more tickets sell than exist. The batch processor reads the inventory count once, then validates the entire queue against that stale snapshot — every request "fits".
reservations.js must re-check against the live count for each request.
Bug report
BUG-OVERSELL · Priority: Critical (refund storm) · Reported by: ticketing
processQueue(store, requests):
- for each requested qty: if store.count >= qty, deduct and record true; otherwise record false
- returns the array of decisions; store.count must end correct
Observed: 5 seats, queue [3, 3] -> both approved, 6 of 5 sold.
Logs
[gate] event 8112: capacity 5, tickets issued 6The code as shipped
src/tickets/reservations.js (editable)
// Processes a queue of reservation requests against the inventory.
exports.processQueue = function (store, requests) {
var available = store.count;
var decisions = [];
for (var i = 0; i < requests.length; i++) {
if (available >= requests[i]) {
store.count = available - requests[i];
decisions.push(true);
} else {
decisions.push(false);
}
}
return decisions;
};
Open the hunt to start the incident clock, edit the files, run the visible tests and submit against the hidden ones, then write the root cause down. More JavaScript bug hunts.