Happy New Year, Dropped Messages — JavaScript Bug Hunt
Inspired by the messaging-app meltdowns every New Year's Eve at midnight, when send queues overflow worldwide.
- Language: JavaScript
- Layer: Backend
- Difficulty: Medium
- Concepts: Queues, Bounds
- Modelled on: WhatsApp NYE
- Visible tests: under capacity just appends; at capacity the oldest is dropped; the queue never exceeds cap
- Reward: 50 XP for a complete fix
Briefing
Inspired by the messaging-app meltdowns every New Year's Eve at midnight, when send queues overflow worldwide. Policy for the bounded outbox: when full, drop the oldest — the newest message is the one the user just hit send on.
outbox.js does the opposite, and its capacity check is off by one.
Bug report
BUG-NYE · Priority: High · Reported by: messaging core
enqueue(queue, msg, cap) rules:
- the returned queue never exceeds cap
- when full, the OLDEST message is dropped to admit the new one
Observed: at capacity the NEW message is silently discarded (users' midnight wishes vanish), and the queue actually grows to cap+1 first.
Logs
[outbox] cap=3 size=4
[outbox] dropped incoming msg id=m5 (queue kept stale m1)The code as shipped
src/msg/outbox.js (editable)
// Bounded send queue. Returns the new queue (never mutates the input).
exports.enqueue = function (queue, msg, cap) {
if (queue.length > cap) {
return queue.slice();
}
return queue.concat([msg]);
};
Open the hunt to edit the files, run the visible tests and submit against the hidden ones. More JavaScript bug hunts.