input.go's reader can leave an orphaned goroutine that's still attempting to read from stdin, also terminal state won't get reset.
- Dominant language
- Go
- Stars
- 569
- Forks
- 364
- Avg merge
- 2d 19h
- Merged PRs (30d)
- 136
Description
A bit of a long title, but this came out of work I was doing to enable `go test -race`.
Basically, input.go's ReadInput() function launches a goroutine, which has these responsibilities:
1. Calls surveyterm.RuneReader.SetTermMode(), to enable raw input (ie, no echo, disables Ctrl+C, Ctrl+Z, etc..).
2. Reads runes in a loop and (eventually) send that via a channel to ReadInput's synchronous path
3. When the goroutine exits, calls RuneReader.RestoreTermMode(), which re-enables echo and all the other things that were disabled.
If the goroutine doesn't exit cleanly it leaves stdin in a weird state. The goroutine will also continue to read from stdin, so it can steal input from other calls to ReadInput().
The fix probably isn't that simple - we need a rune reader that's "context aware", so it can properly cancel, or we need to figure out a way to pass a stream we can safely close (ie, NOT os.Stdin!), so we can unblock .ReadRune().
(or maybe something even better, these are just off the top of my head)
Contributor guide
Research direction
Start by reading input.go's ReadInput function and the surveyterm.RuneReader SetTermMode and RestoreTermMode calls. Reproduce the goroutine and terminal-state behavior under go test -race, then trace how ReadRune is blocked and how a cancelled read could be unblocked without closing os.Stdin. Done means no orphaned reader remains, terminal state is restored, and later ReadInput calls do not lose input.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- cli
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Active
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100