Skip to content
Myr

Fix spurious exit while waiting for a key with --listen

Before adoption: this commit came in with the history the project adopted, so no landing records it.

- getch() charged EINTR against a 100 iteration limit meant for read attempts, and the count only reset once a byte was read - So signals arriving during an idle prompt drained it, and running out returned getCharError, which became Event{Fatal} and exit status 2 - Only the cancellable path is affected, hence only --listen - select() is not restarted by SA_RESTART, unlike the blocking read on the non-cancellable path, so it is the only one that sees EINTR - waitReadable() already retries EINTR without a limit Fix #4917

authored by Junegunn Choi · committed by Junegunn Choi · parent 63e82a9 · Browse files · 2 files+3 added−3 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+3 added−3 removed

  • other:+3 added−3 removed

2 files+3 added−3 removed

modified:src/tui/light_unix.go+3 added-2 removed
238 unmodified lines
239 wpipe.Close()240 }()241242 cancelFd := int(rpipe.Fd())243 for range maxSelectTries {243 for {244 var rfds unix.FdSet245 limit := len(rfds.Bits) * unix.NFDBITS246 if fd >= limit || cancelFd >= limit {247 return getter()
2 unmodified lines
250 rfds.Set(fd)251 rfds.Set(cancelFd)252 _, err := unix.Select(max(fd, cancelFd)+1, &rfds, nil, nil, nil)253 if err != nil {254 // An interrupted wait is not a failed read, so it must not count255 // against anything. Retry until the fd is ready or the wait fails.256 if err == syscall.EINTR {257 continue258 }259 return 0, getCharError
6 unmodified lines
266 if rfds.IsSet(fd) {267 return getter()268 }269 }268 return 0, getCharError270}271272func (r *LightRenderer) Size() TermSize {273 ws, err := unix.IoctlGetWinsize(int(r.ttyin.Fd()), unix.TIOCGWINSZ)
5 unmodified lines
modified:src/tui/light.go-1 removed
25 unmodified lines
26 offsetPollTries = 1027 queryTimeout = 500 * time.Millisecond28 maxInputBuffer = 1024 * 102429 escapeLookback = 25630 maxSelectTries = 10030)3132const DefaultTtyDevice string = "/dev/tty"33
1659 unmodified lines