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

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 6

The 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 edit the files, run the visible tests and submit against the hidden ones. More JavaScript bug hunts.