Code Room
Code reviewMediumcr-g001
Subject Goroutine leaksLevel Mid–Senior~25 minCommon in Code quality & review interviewsIndustries Software development

Question

Review this Go fan-out worker that queries replicas and returns the first response.

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 firstReply(ctx context.Context, replicas []string) (string, error) {	results := make(chan string)	for _, addr := range replicas {		go func(a string) {			resp, err := query(ctx, a)			if err == nil {				results <- resp			}		}(addr)	}	select {	case r := <-results:		return r, nil	case <-ctx.Done():		return "", ctx.Err()	}}
Run or narrate your approach, then ask the coach.