bee
bee copied to clipboard
a possible coroutine leak
The start function in the watch.go file uses <-started
at the end, so the operation will block the coroutine exit, and the reload function may call the start function multiple times, causing the coroutine to leak.
@bdjimmy i test it .
when file change , after reload runtime.NumGoroutine()
add 1 .
I think this is in line with expectations。
add new coroutine for run new app .
and all last coroutine (start by func Start(appname string)
) will blocking at
started <- true
you can add a log before started <- true
like
beeLogger.Log.Successf("NumGoroutine:%d...", runtime.NumGoroutine())
After all, debug is not a normal release run
// Kill kills the running command process
func Kill() {
defer func() {
if e := recover(); e != nil {
beeLogger.Log.Infof("Kill recover: %s", e)
}
}()
if cmd != nil && cmd.Process != nil {
// Windows does not support Interrupt
if runtime.GOOS == "windows" {
cmd.Process.Signal(os.Kill)
} else {
cmd.Process.Signal(os.Interrupt)
}
ch := make(chan struct{}, 1)
go func() {
cmd.Wait()
ch <- struct{}{}
}()
select {
case <-ch:
<-started
return
case <-time.After(10 * time.Second):
beeLogger.Log.Info("Timeout. Force kill cmd process")
err := cmd.Process.Kill()
if err != nil {
beeLogger.Log.Errorf("Error while killing cmd process: %s", err)
}
<-started
return
}
}
}
i read started cmd.kill ,and NumGoroutine
always 10 . but i don't test cmd==nil
. I'm going to do more testing