Skip to content

Commit 3290dbe

Browse files
committed
fix: reap child processes on session stop/kill to prevent zombies
captureOutput goroutine could exit via the done channel without calling cmd.Wait(), leaving terminated child processes as zombies in the process table. Moved cmd.Wait() and p.Close() into a defer so the child is always reaped regardless of exit path.
1 parent bbd4c20 commit 3290dbe

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

internal/daemon/server.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,11 @@ func (s *Server) captureOutput(name string, h *sessionHandle) {
477477

478478
f := p.File()
479479

480+
defer func() {
481+
cmd.Wait()
482+
p.Close()
483+
}()
484+
480485
if detector != nil {
481486
defer func() {
482487
if pending := detector.Flush(); len(pending) > 0 {
@@ -513,13 +518,10 @@ func (s *Server) captureOutput(name string, h *sessionHandle) {
513518
}
514519
}
515520
if err != nil && !isTimeout(err) {
516-
break
521+
return
517522
}
518523
}
519524

520-
cmd.Wait()
521-
p.Close()
522-
523525
s.mu.Lock()
524526
defer s.mu.Unlock()
525527

0 commit comments

Comments
 (0)