The Zune Freeze — Java Bug Hunt
Inspired by December 31st, 2008 — the day every Microsoft Zune froze.
- Language: Java
- Layer: Backend
- Difficulty: Medium
- Concepts: Dates, Leap Years
- Modelled on: Microsoft Zune · 2008
- Visible tests: day one is January 1st, 1980; day 366 of a leap year stays in that year; day 367 starts the next year
- Reward: 50 XP for a complete fix
Incident
- Severity: SEV-1 (priority: Critical)
- Ticket: BUG-Z2K8
- Reported by: everyone, on New Year's Eve
- Time to fix: 20 minutes, the target for a medium incident
Failing checks on the shipped build
- day 366 of a leap year stays in that year — Dec 31, 1980: expected [1980, 366] but got [1981, 0]
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 December 31st, 2008 — the day every Microsoft Zune froze. The firmware's days-since-1980 conversion mishandled the 366th day of a leap year, and the players locked up until the calendar bailed them out.
ZuneClock.java converts a day count into (year, dayOfYear). Day 366 of a leap year currently rolls into the next year.
Bug report
BUG-Z2K8 · Priority: Critical · Reported by: everyone, on New Year's Eve
toDate(daysSince1980) — days start at 1 on Jan 1, 1980:
- toDate(1) -> [1980, 1]
- toDate(366) -> [1980, 366] (1980 is a leap year!)
- toDate(367) -> [1981, 1]
Observed: day 366 returns [1981, 0].
Logs
[zune] boot day=10593 -> year=2009 dayOfYear=0 (expected 2008 / 366)The code as shipped
ZuneClock.java (editable)
class ZuneClock {
static boolean isLeap(int year) {
return year % 4 == 0 && (year % 100 != 0 || year % 400 == 0);
}
// days: 1-based count of days since Jan 1, 1980.
static int[] toDate(int days) {
int year = 1980;
while (true) {
int len = isLeap(year) ? 366 : 365;
if (days > 365) {
days -= len;
year++;
} else {
break;
}
}
return new int[] { year, days };
}
}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.