Gangnam Style Broke the Counter — Java Bug Hunt
Inspired by 2014, when PSY's "Gangnam Style" blew past 2,147,483,647 views and YouTube publicly admitted their view counter needed an upgrade to 64 bits.
- Language: Java
- Layer: Backend
- Difficulty: Easy
- Concepts: Overflow, Counters
- Modelled on: YouTube · 2014
- Visible tests: ordinary counting works; crossing two billion keeps counting up
- Reward: 50 XP for a complete fix
Incident
- Severity: SEV-3
- Time to fix: 10 minutes, the target for an easy incident
Failing checks on the shipped build
- crossing two billion keeps counting up — expected 2147493000 but got -2147474296
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 request through the handler, the validation and the service it calls; find the first step whose output disagrees with the report.
- 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 2014, when PSY's "Gangnam Style" blew past 2,147,483,647 views and YouTube publicly admitted their view counter needed an upgrade to 64 bits.
ViewCounter.java is still on the old math.
Bug report
BUG-PSY · Reported by: analytics
addViews(current, delta) must keep counting past Integer.MAX_VALUE. Observed: the most-watched video on the platform reports -2,147,473,648 views.
Logs
[stats] video=9bZkp7q19f0 views=-2147473648The code as shipped
ViewCounter.java (editable)
class ViewCounter {
static long addViews(long current, long delta) {
int next = (int) current + (int) delta;
return next;
}
}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 Java bug hunts.