Simplify Wait() implementation based on code review feedback

Remove unnecessary exited() check - we should always call cmd.Wait()
in the sync.Once block to properly reap the process and capture its
exit status. The sync.Once ensures it's only called once.

Co-authored-by: ncw <536803+ncw@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2025-10-30 18:03:48 +00:00
parent 4f5efe2871
commit a58efc1544

View File

@@ -181,10 +181,8 @@ func (s *sshSessionExternal) Wait() error {
// Use sync.Once to ensure we only wait for the process once // Use sync.Once to ensure we only wait for the process once
// This prevents zombie processes that occur when Wait() is called multiple times // This prevents zombie processes that occur when Wait() is called multiple times
s.waitOnce.Do(func() { s.waitOnce.Do(func() {
if s.exited() { // Always call cmd.Wait() to properly reap the process
s.waitErr = nil // even if it has already exited
return
}
s.waitErr = s.cmd.Wait() s.waitErr = s.cmd.Wait()
if s.waitErr == nil { if s.waitErr == nil {
fs.Debugf(s.f, "ssh external: command exited OK") fs.Debugf(s.f, "ssh external: command exited OK")