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 摘要。