Code RoomCircuit breaker never resets
HardPrep Room Coding #1727

Circuit breaker never resets

Code reviewCode quality & reviewSenior–Staff~35 min

Review this Go circuit breaker.

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 35 min
Mark a line and say what kind of problem it is.0 findings
1type Breaker struct {
2 failures int
3 open bool
4 openedAt time.Time
5}
6 
7func (b *Breaker) Call(fn func() error) error {
8 if b.open && time.Since(b.openedAt) < 30*time.Second {
9 return ErrOpen
10 }
11 err := fn()
12 if err != nil {
13 b.failures++
14 if b.failures >= 5 {
15 b.open = true
16 b.openedAt = time.Now()
17 }
18 return err
19 }
20 b.failures = 0
21 return nil
22}
Which questions mattered is sealed until you submit. Telling you now would just be handing over the edge cases.