🐛 Trying to fix produce of defunct processes

This commit is contained in:
2024-10-06 11:29:32 +08:00
parent 2240ac30c6
commit a11af366ef
2 changed files with 12 additions and 6 deletions

View File

@@ -104,15 +104,18 @@ func (v *AppInstance) Stop() error {
log.Warn().Int("pid", v.Cmd.Process.Pid).Err(err).Msgf("Failed to send SIGTERM to process...")
if err = v.Cmd.Process.Kill(); err != nil {
log.Error().Int("pid", v.Cmd.Process.Pid).Err(err).Msgf("Failed to kill process...")
} else {
v.Cmd = nil
return err
}
return err
} else {
v.Cmd = nil
}
}
// We need to wait for the process to exit
// The wait syscall will read the exit status of the process
// So that we don't produce defunct processes
// Refer to https://stackoverflow.com/questions/46293435/golang-exec-command-cause-a-lot-of-defunct-processes
_ = v.Cmd.Wait()
v.Cmd = nil
v.Status = AppExited
return nil
}