Code Room
Code reviewMediumcr-g423
Subject Race conditionsLevel Mid–Senior~24 minCommon in Concurrency interviewsIndustries Software development

Question

Review this Go connection pool that lazily dials and memoizes one connection per host.

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
type Pool struct {	mu    sync.Mutex	conns map[string]*Conn} func (p *Pool) Get(host string) *Conn {	p.mu.Lock()	c, ok := p.conns[host]	p.mu.Unlock()	if ok {		return c	}	c = dial(host)            // slow I/O, outside the lock	p.mu.Lock()	p.conns[host] = c	p.mu.Unlock()	return c}
Run or narrate your approach, then ask the coach.