#Finding goroutine leak

10 messages · Page 1 of 1 (latest)

fossil hound
#

maybe use defer t.stop() so ticker always stops regardless of how or why it exits

main turtle
#

put defer t.Stop() directly after the ticker construction

fossil hound
#

i think you should put it inside the go func routine?

#

since the monitor func would return, thus t.stop would be called despite how it's gonna be used by the other go routine that just started

main turtle
#

true

#

why is the ticker constructed outside of the goroutine anyway

fossil hound
#

actually good point

#

personally i dont like functions that spin their own routine
i much prefer if the function is blocking, it's so effortless to put it in a routine if i need it be, or dont, if i have no such needs

#

blocking functions also allow error to bubble up
instead of calling loggers
you can just return the error
the caller who decided to stuck this into a go routine can decide how to handle as they see fit

#

you can also do post events

go func(){
  setup()
  err := blockingFunc()
  if err != nil {
    handleErr(err)
  }
  cleanup()
}