In the code below, a client is putting a string on a service's input channel and listening for a reply on either an output or an error channel.
The context is set with a 5ms timeout.
func (s service) run() {
<-s.input
go func() {
select {
case <-s.ctx.Done():
s.errs <- errors.New("ctx done")
return
}
}()
time.Sleep(10 * time.Millisecond)
s.output <- 42
fmt.Println("run exit")
}
The code times out correctly (due to the 10ms sleep) and outputs
error: ctx done
However, the "run exit" is never printed.
Question: Is there a goroutine leak with processes stuck on
s.output <- 42
Go Playground example