Fix preview process not killed on exit
CodeQL / Analyze (go) (push) Has been cancelled
build / build (push) Has been cancelled
Test fzf on macOS / build (push) Has been cancelled

Thanks to @LangLangBart for the investigation and the suggested fix.

Fix #4667
This commit is contained in:
Junegunn Choi
2026-02-01 11:32:04 +09:00
parent 6360c9261c
commit bc8967632b
+5 -1
View File
@@ -411,6 +411,7 @@ type Terminal struct {
suppress bool suppress bool
startChan chan fitpad startChan chan fitpad
killChan chan bool killChan chan bool
killedChan chan bool
serverInputChan chan []*action serverInputChan chan []*action
callbackChan chan versionedCallback callbackChan chan versionedCallback
bgQueue map[action][]func(bool) bgQueue map[action][]func(bool)
@@ -1101,6 +1102,7 @@ func NewTerminal(opts *Options, eventBox *util.EventBox, executor *util.Executor
theme: opts.Theme, theme: opts.Theme,
startChan: make(chan fitpad, 1), startChan: make(chan fitpad, 1),
killChan: make(chan bool), killChan: make(chan bool),
killedChan: make(chan bool),
serverInputChan: make(chan []*action, 100), serverInputChan: make(chan []*action, 100),
callbackChan: make(chan versionedCallback, maxBgProcesses), callbackChan: make(chan versionedCallback, maxBgProcesses),
bgQueue: make(map[action][]func(bool)), bgQueue: make(map[action][]func(bool)),
@@ -5031,6 +5033,7 @@ func (t *Terminal) toggleItem(item *Item) bool {
func (t *Terminal) killPreview() { func (t *Terminal) killPreview() {
select { select {
case t.killChan <- true: case t.killChan <- true:
<-t.killedChan
default: default:
} }
} }
@@ -5396,6 +5399,7 @@ func (t *Terminal) Loop() error {
case immediately := <-t.killChan: case immediately := <-t.killChan:
if immediately { if immediately {
util.KillCommand(cmd) util.KillCommand(cmd)
t.killedChan <- true
} else { } else {
// We can immediately kill a long-running preview program // We can immediately kill a long-running preview program
// once we started rendering its partial output // once we started rendering its partial output
@@ -5642,10 +5646,10 @@ func (t *Terminal) Loop() error {
}) })
} }
t.eventBox.Set(EvtQuit, quitSignal{code, nil})
t.running.Set(false) t.running.Set(false)
t.killPreview() t.killPreview()
cancel() cancel()
t.eventBox.Set(EvtQuit, quitSignal{code, nil})
}() }()
looping := true looping := true