abiosoft / abiosoft/ishell

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

Abierto
#78 6 comentarios 0 reacciones 0 asignados Ver en GitHub
bug
Lenguaje dominante
Go
Estrellas
1.8k
Forks
213
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

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.

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.