Code Room
Code reviewHardcr-g324
Subject Error handlingLevel Senior–Staff~22 minCommon in Code quality & review interviewsIndustries Software development, Technology

Question

Review this Go function that fans out a per-shard query and waits for all results with a deadline.

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.

Talk through your review
Code to reviewgo
func queryAll(ctx context.Context, shards []Shard) ([]Row, error) {    out := make(chan Row, len(shards))    for _, s := range shards {        go func(s Shard) {            r, _ := s.Query(context.Background())            out <- r        }(s)    }    var rows []Row    for i := 0; i < len(shards); i++ {        select {        case r := <-out:            rows = append(rows, r)        case <-ctx.Done():            return nil, ctx.Err()        }    }    return rows, nil}
Run or narrate your approach, then ask the coach.