fix(process): emit kill action immediately

Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
Virgil 2026-03-31 19:33:51 +00:00
parent 9a93ebea66
commit c60f355b25
2 changed files with 27 additions and 4 deletions

View file

@ -38,6 +38,7 @@ type ManagedProcess struct {
gracePeriod time.Duration
killGroup bool
lastSignal string
killEmitted bool
}
// Process is kept as a compatibility alias for ManagedProcess.
@ -219,3 +220,14 @@ func (p *ManagedProcess) requestedSignal() string {
defer p.mu.RUnlock()
return p.lastSignal
}
func (p *ManagedProcess) markKillEmitted() bool {
p.mu.Lock()
defer p.mu.Unlock()
if p.killEmitted {
return false
}
p.killEmitted = true
return true
}

View file

@ -230,10 +230,7 @@ func (s *Service) StartWithOptions(ctx context.Context, opts RunOptions) core.Re
close(proc.done)
if status == StatusKilled {
_ = s.Core().ACTION(ActionProcessKilled{
ID: id,
Signal: killedSignal,
})
s.emitKilledAction(proc, killedSignal)
}
s.Core().ACTION(ActionProcessExited{
ID: id,
@ -308,6 +305,7 @@ func (s *Service) Kill(id string) error {
if err := proc.Kill(); err != nil {
return err
}
s.emitKilledAction(proc, proc.requestedSignal())
return nil
}
@ -490,3 +488,16 @@ func normalizeSignalName(sig syscall.Signal) string {
return sig.String()
}
}
func (s *Service) emitKilledAction(proc *ManagedProcess, signal string) {
if proc == nil || !proc.markKillEmitted() {
return
}
if signal == "" {
signal = "SIGKILL"
}
_ = s.Core().ACTION(ActionProcessKilled{
ID: proc.ID,
Signal: signal,
})
}