abiosoft / abiosoft/ishell

Leaves terminal in raw mode when calling shell.Close() asynchronously

未关闭
#78 6 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
bug
主要语言
Go
星标
1.8k
派生
213
PR 合并指标
30 天内没有已合并 PR

描述

When calling `shell.Close()` when from a goroutine, my terminal becomes unresponsive (echo is disabled) and I have to call "reset" to make it work again.

What I suspect that happens, is that
- `run()` (indirectly) calls readline, which switches the terminal into raw mode
- `run()` then waits for a line to be read, or a message on `haltChan`
- `shell.Close()` posts a message to `haltChan`, which makes `run()` return
- The readline is still running in a goroutine, when the program terminates, leaving the terminal in raw mode.

Given that goroutines that are still running when the program exits are interrupted, without running their defers (AFAIU), this seems something that ishell should fix, not readline. However, it's not entirely clear to me how to tell readline about this. It seems that calling `Close()` on the readline lib might help (which calls `Terminal.Close()` which exits raw mode, and also closes stdin, which should cause the reader to return and cleanup).

However, I tried this, and it didn't actually help. I called `s.reader.scanner.Close()` at the end of `Shell.run()`, but that seemed to block, or not help. Investigating shows that `Terminal.close()` also closes stdin, and then waits for its ioloop goroutine to finish, but it seems that the actual stdin read does not return (I would expect it to return an EOF error, though I'm not entirely sure how `bufio.Reader.ReadRune()`, which is used, is supposed to handle this). Since the ioloop doesn't finish, `Terminal.Close()` blocks and never gets around to resetting the terminal. I have no more time to dig into this, unfortunately.

贡献指南

这个仓库没有索引到贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。