Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't use the wrong PID in error strings #4530

Merged
merged 1 commit into from
Jun 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions pkg/supervisor/supervisor_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ Loop:
if errors.Is(err, syscall.ESRCH) {
return nil
} else if err != nil {
return fmt.Errorf("failed to send SIGTERM to pid %d: %w", s.cmd.Process.Pid, err)
return fmt.Errorf("failed to send SIGTERM: %w", err)
}
case <-deadline:
break Loop
Expand All @@ -88,7 +88,7 @@ Loop:
if errors.Is(err, syscall.ESRCH) {
return nil
} else if err != nil {
return fmt.Errorf("failed to send SIGKILL to pid %d: %w", s.cmd.Process.Pid, err)
return fmt.Errorf("failed to send SIGKILL: %w", err)
}
return nil
}
Expand All @@ -115,15 +115,19 @@ func (s *Supervisor) maybeKillPidFile(check <-chan time.Time, deadline <-chan ti
return fmt.Errorf("failed to parse pid file %s: %w", s.PidFile, err)
}

return s.killPid(p, check, deadline)
if err := s.killPid(p, check, deadline); err != nil {
return fmt.Errorf("failed to kill process with PID %d: %w", p, err)
}

return nil
}

func (s *Supervisor) shouldKillProcess(pid int) (bool, error) {
cmdline, err := os.ReadFile(filepath.Join(s.ProcFSPath, strconv.Itoa(pid), "cmdline"))
if os.IsNotExist(err) {
return false, nil
} else if err != nil {
return false, fmt.Errorf("failed to read process %d cmdline: %w", pid, err)
return false, fmt.Errorf("failed to read process cmdline: %w", err)
}

// only kill process if it has the expected cmd
Expand All @@ -137,7 +141,7 @@ func (s *Supervisor) shouldKillProcess(pid int) (bool, error) {
if os.IsNotExist(err) {
return false, nil
} else if err != nil {
return false, fmt.Errorf("failed to read process %d environ: %w", pid, err)
return false, fmt.Errorf("failed to read process environ: %w", err)
}

for _, e := range strings.Split(string(env), "\x00") {
Expand Down
Loading