charmbracelet / charmbracelet/bubbletea

The input isn't verified before using epoll on it

Open
#964 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
44.9k
Forks
1.3k
PR merge metrics
No merged PRs in 30d

Description

## Describe the bug
Bubbletea doesn't validate given [`input`](https://github.com/charmbracelet/bubbletea/blob/7199a7f29d83838b7edb4d86e024a6060624048d/tea.go#L150), before trying to use epoll on it:

https://github.com/charmbracelet/bubbletea/blob/7199a7f29d83838b7edb4d86e024a6060624048d/tty.go#L55

When running processes, Golang (maybe other langs as well?) gives by default [the `/dev/null` as the stdin](https://github.com/golang/go/blob/25aa45afcf40ff6c699b47bad0cb609bba84da12/src/os/exec/exec.go#L178).

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 https://github.com/muesli/cancelreader/pull/13 to see the underlying `syscall.Errno: EPERM`. Looking at [epoll_ctl(2)](https://man7.org/linux/man-pages/man2/epoll_ctl.2.html), 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
1. Run test: `go test -count=1 ./spin2sec_test.go`
1. 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: https://github.com/wavesoftware/go-magetasks/commit/7496084d8caa1e7361bf806224b2cd95e12a9e1d.

Contributor guide

Open the contributing guide

Research direction

Start in tea.go at the input definition and tty.go where the input is passed to the cancelreader and epoll. Reproduce the failure with `go test -count=1 ./spin2sec_test.go` using the linked repro, then trace how `/dev/null` is handled. Done means the common `/dev/null` stdin case no longer produces the epoll error while normal input continues to work.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, linux
Domain
cli, operating-systems
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.