Code RoomNil channel disables select branch
HardPrep Room Coding #1870

Nil channel disables select branch

Code reviewCode quality & reviewSenior–Staff~40 min

Review this Go event loop that disables a branch by nil-ing a channel.

The author disables a branch by setting the channel to nil. Where's the concurrency/lifecycle bug?

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 40 min
Mark a line and say what kind of problem it is.0 findings
1func loop(in <-chan int, done <-chan struct{}) {
2 var ticks <-chan time.Time
3 ticker := time.NewTicker(time.Second)
4 ticks = ticker.C
5 for {
6 select {
7 case v := <-in:
8 if v < 0 {
9 ticks = nil // (1) disable ticks branch
10 }
11 handle(v)
12 case <-ticks:
13 flush()
14 case <-done:
15 ticker.Stop()
16 return // (2)
17 }
18 }
19}
Which questions mattered is sealed until you submit. Telling you now would just be handing over the edge cases.