Skip to content

Commit

Permalink
update: avoid zombie process when restarting into update bin
Browse files Browse the repository at this point in the history
  • Loading branch information
sni committed Jun 12, 2024
1 parent 66afbdf commit b32af9c
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
13 changes: 12 additions & 1 deletion pkg/snclient/snclient_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,18 @@ func (snc *Agent) finishUpdate(binPath, mode string) {
if mode == "update" {
cmd := exec.Command(binPath, "update", "apply")
cmd.Env = os.Environ()
_ = cmd.Start()
err := cmd.Start()
if err != nil {
log.Errorf("failed to start update apply: %s", err.Error())

return
}
go func() {
err := cmd.Wait()
if err != nil {
log.Errorf("update apply failed: %s", err.Error())
}
}()

return
}
Expand Down
13 changes: 12 additions & 1 deletion pkg/snclient/snclient_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,18 @@ func (snc *Agent) finishUpdate(binPath, mode string) {
if mode == "update" {
cmd := exec.Command(binPath, "update", "apply")
cmd.Env = os.Environ()
_ = cmd.Start()
err := cmd.Start()
if err != nil {
log.Errorf("failed to start update apply: %s", err.Error())

return
}
go func() {
err := cmd.Wait()
if err != nil {
log.Errorf("update apply failed: %s", err.Error())
}
}()

return
}
Expand Down
6 changes: 6 additions & 0 deletions pkg/snclient/task_updates.go
Original file line number Diff line number Diff line change
Expand Up @@ -761,6 +761,12 @@ func (u *UpdateHandler) Apply(bin string) error {
if err != nil {
return fmt.Errorf("starting updater failed: %s", err.Error())
}
go func() {
err := cmd.Wait()
if err != nil {
log.Errorf("update failed: %s", err.Error())
}
}()

return nil
}
Expand Down

0 comments on commit b32af9c

Please sign in to comment.