Case of a leaking timer in go
It was only an accident that I read a post on ArangoDB site and found the same leak in one of our projects at work. So this is going to be quite short, but nevertheless I want for have it in form of a blogpost. Here is how leak looked like: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 package main import ( "fmt" "runtime" "time" ) func main() { messags := make(chan string) for { select { case msg := <- messages: // do smth with msg fmt.Println(msg) return msg case <-time.After(time.Second * 3): // do smth else fmt.Println("3 sec timer fired") case <-time.After(time.Second * 30): fmt.Println("30 sec timer fired") return } } } What is wrong with it? There is a lot: ...