c-bata / go-prompt

Building powerful interactive prompts in Go, inspired by python-prompt-toolkit.
https://godoc.org/github.com/c-bata/go-prompt
MIT License
5.29k stars 348 forks source link

[Bug] `prompt.Input` leaks file descriptor of "/dev/tty" #253

Open avi-mastov opened 2 years ago

avi-mastov commented 2 years ago

Bug reports

prompt.Input leaks file descriptor of "/dev/tty"

Expected Behavior

Close the file descriptor when the function returns.

Current Behavior and Steps to Reproduce

Each call to prompt.Input creates a New Prompt with NewStandardInputParser, which, for posix OS calls syscall.Open on "/dev/tty". The opened file descriptor is never closed, which causes a resource leak.

Context

I want to manage the input loop myself, but each time I call prompt.Input, it leaks another file descriptor. I found a workaround by creating a New Prompt and using its Input method, but I need to define a dummy executor that does nothing, just so I can call the New function.