Code RoomFetch results race and corrupt
HardPrep Room Coding #1686

Fetch results race and corrupt

Code reviewConcurrencyCode quality & reviewSenior–Staff~25 min

Review this Go code that fans out one goroutine per URL and collects results. (Assume Go 1.21.)

What a strong answer looks like

Separate real bugs from style. Rank issues by severity, point at the root cause rather than the symptom, and suggest a concrete fix, specific and kind.

0:00 of about 25 min
Mark a line and say what kind of problem it is.0 findings
1func fetchAll(urls []string) []string {
2 var wg sync.WaitGroup
3 results := make([]string, 0)
4 for _, u := range urls {
5 wg.Add(1)
6 go func() {
7 defer wg.Done()
8 results = append(results, fetch(u))
9 }()
10 }
11 wg.Wait()
12 return results
13}
Which questions mattered is sealed until you submit. Telling you now would just be handing over the edge cases.