🐛 Trying to fix produce of defunct processes
This commit is contained in:
parent
2240ac30c6
commit
a11af366ef
@ -4,6 +4,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"git.solsynth.dev/goatworks/roadsign/pkg/warden"
|
"git.solsynth.dev/goatworks/roadsign/pkg/warden"
|
||||||
|
"github.com/rs/zerolog/log"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@ -45,7 +46,9 @@ func doPublish(c *fiber.Ctx) error {
|
|||||||
var instance *warden.AppInstance
|
var instance *warden.AppInstance
|
||||||
if application != nil {
|
if application != nil {
|
||||||
if instance = warden.GetFromPool(application.ID); instance != nil {
|
if instance = warden.GetFromPool(application.ID); instance != nil {
|
||||||
_ = instance.Stop()
|
if err := instance.Stop(); err != nil {
|
||||||
|
log.Warn().Err(err).Str("id", application.ID).Msg("Failed to stop application when publishing...")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else if destination != nil && destination.GetType() != navi.DestinationStaticFile {
|
} else if destination != nil && destination.GetType() != navi.DestinationStaticFile {
|
||||||
return fiber.ErrUnprocessableEntity
|
return fiber.ErrUnprocessableEntity
|
||||||
|
@ -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...")
|
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 {
|
if err = v.Cmd.Process.Kill(); err != nil {
|
||||||
log.Error().Int("pid", v.Cmd.Process.Pid).Err(err).Msgf("Failed to kill process...")
|
log.Error().Int("pid", v.Cmd.Process.Pid).Err(err).Msgf("Failed to kill process...")
|
||||||
} else {
|
return err
|
||||||
v.Cmd = nil
|
|
||||||
}
|
}
|
||||||
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
|
v.Status = AppExited
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user