Skip to content

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

Open
@matthijskooijman

Description

@matthijskooijman

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions