The Zune Freeze

Medium

· Backend

Incident

SEV-1

BUG-Z2K8

Priority: Critical · reported by everyone, on New Year's Eve

Time to fix: 20 min

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

  1. Read the report: write down the expected behaviour and the actual one in a sentence each.
  2. Reproduce it: run the visible tests and find the failing check that matches the report.
  3. 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.
  4. Follow the request through the handler, the validation and the service it calls; find the first step whose output disagrees with the report.
  5. Fix the cause rather than the symptom, run the visible tests again, and submit against the hidden ones — then write the root cause down.

Inspired by

Microsoft Zune · 2008

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.

Code map

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 };
    }
}

Sign in to edit the file, run the tests and submit a fix

A free account — no card, no trial clock. You come straight back here.

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

  1. Read the report: write down the expected behaviour and the actual one in a sentence each.
  2. Reproduce it: run the visible tests and find the failing check that matches the report.
  3. 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.
  4. Follow the request through the handler, the validation and the service it calls; find the first step whose output disagrees with the report.
  5. 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.