fix: close the TTY files opened for input when Run returns (#1855)

Co-authored-by: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
draw me an elephant 2026-11-12 08:25:49 -05:00 committed by GitHub
parent 12b7b4d0eb
commit 13fb42d8ea
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

9
tea.go
View file

@ -1083,10 +1083,17 @@ func (p *Program) Run() (returnModel Model, returnErr error) {
} else if p.input == nil {
p.input = os.Stdin
if !term.IsTerminal(os.Stdin.Fd()) {
ttyIn, _, err := OpenTTY()
ttyIn, ttyOut, err := OpenTTY()
if err != nil {
return p.initialModel, fmt.Errorf("bubbletea: error opening TTY: %w", err)
}
// Nothing else owns these files: close them when Run returns so
// each Run doesn't leak a /dev/tty fd (on Windows, CONIN$ and
// CONOUT$ handles).
defer func() {
_ = ttyIn.Close()
_ = ttyOut.Close()
}()
p.input = ttyIn
}
}