charmbracelet/bubbletea

The input isn't verified before using epoll on it

cardil opened this issue · 3 comments

Describe the bug

Bubbletea doesn't validate given input, before trying to use epoll on it:

p.cancelReader, err = newInputReader(p.input)

When running processes, Golang (maybe other langs as well?) gives by default the /dev/null as the stdin.

This in turn causes a cryptic epoll error, as the /dev/null doesn't support epoll:

error creating cancelreader: add reader to epoll interest list

You could use muesli/cancelreader#13 to see the underlying syscall.Errno: EPERM. Looking at epoll_ctl(2), the EPERM is returned if:

The target file fd does not support epoll. This error can occur if fd refers to, for example, a regular file or a directory.

Setup

Please complete the following information along with version numbers, if applicable.

  • OS: Linux
  • Shell: zsh
  • Terminal Emulator: Tilix
  • Terminal Multiplexer: none

To Reproduce

Steps to reproduce the behavior:

  1. Checkout the repro: https://github.com/cardil/bubbletea-964
  2. Run test: go test -count=1 ./spin2sec_test.go
  3. You should see TestSpin2SecFailing test failing, with error:
    error creating cancelreader: add reader with descriptor 0 to epoll interest list: operation not permitted
    

Expected behavior

Bubbletea should address a common case of having /dev/null as input, and not feed it to epoll-based reader.

Walk around

To walk away of this problem, one might consider giving an empty buffer as process stdin. See, an example: wavesoftware/go-magetasks@7496084.

This (most likely) causes the #797