Description
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 moderun()
then waits for a line to be read, or a message onhaltChan
shell.Close()
posts a message tohaltChan
, which makesrun()
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.