deno icon indicating copy to clipboard operation
deno copied to clipboard

killing a process does not return tty from raw mode

Open andykais opened this issue 2 years ago • 1 comments

given the following code snippet

async function* read_input() {
  while (true) {
    const buffer = new Uint8Array(1024);
    Deno.setRaw(Deno.stdin.rid, true);
    const length = <number>await Deno.stdin.read(buffer);
    Deno.setRaw(Deno.stdin.rid, false);
    yield buffer
  }
}

for await (const input of read_input()) {
  console.log(input)
}

if I run pkill deno in another terminal, I am left with a terminal that is still in raw mode. This means I cannot type things like Ctrl + c anymore. Its possible that deno is functioning as expected here, not doing any graceful shutdown things when the process is killed. This does come up fairly commonly though however, if I am developing a cli app with keyboard input and I need to stop the process. Essentially it means opening up a new terminal later

andykais avatar Jul 29 '22 02:07 andykais

the same thing appears to happen when the process exits unexpectedly, though I am having a harder time reproing that

andykais avatar Jul 29 '22 04:07 andykais

You can listen to sigint signal and do the cleanup there

sigmaSd avatar Jul 31 '22 17:07 sigmaSd

I believe I cannot based on this issue here: https://github.com/denoland/deno/issues/15479. I will close this issue though because the issue with closing the resource is better outlined there. If that is solved, then I will simply listen for the sigint signal like you outlined

andykais avatar Aug 29 '22 16:08 andykais