Go select, sync, and context

R-GOSEL-V4-3hard

Cancel what you started

A downloader searches several mirrors for one usable response. Native sleeps/timers model response delays; no network I/O occurs. The supplied launch wrapper counts unfinished mirror tasks, not process-wide runtime goroutines, and the report samples it 150 ms after search returns. Keep that visible ownership accounting or an equivalent completion receipt. Medium uses short delays of at most 120 ms; its task is abandoned-send cleanup after those fetches finish. Hard includes slow cooperative fetches and an optional fourth mirror field giving its attempt budget in ms (default 1000). A failed attempt returns an empty name; it is not a usable answer. Deadline reporting allows 50 ms delivery slack. Supported response delays, deadlines and attempt budgets are integers from 0 to 1000 ms. Graded timings are separated from other replies/deadlines; expected fastest response and cleanup assume ordinary scheduling.

What needs to change

Each mirror now has its own attempt budget as well as the parent search deadline. Continue past failed attempts to the first usable answer, or report timeout when none can succeed. Once the search finishes, cancel its remaining cooperative work and leave no owned tasks at the report.

Reproduce

  1. Run the program with the sample stdin: one 40 ms mirror and two very slow ones.

Acceptance criteria

Your review marks · Saved in this browser. Test acceptance is tracked separately.

Notes

Review fetch and search. Each attempt selects on response time and its budget context; an empty name is a failed attempt.

The deadline context is created in main and passed to search.

The supplied active counter samples owned tasks after 150 ms. Mirror’s optional BudgetMs defaults to 1000.

Sign in to open this exercise

The ticket brief is public. Sign in to access the exercise. Paid exercises require Pro.

Sign in