crossterm-rs / crossterm

Cross platform terminal library rust
MIT License
3.29k stars 280 forks source link

Use of `/dev/tty` on WSL2 may be problemmatic #764

Open bruceg opened 1 year ago

bruceg commented 1 year ago

Describe the bug When using vector top in WSL2 with Windows Terminal, one of the first display cycles hangs in the kernel for almost two minutes. I have traced this down to the kernel stalling when opening /dev/tty in the size function. This stall does not happen the first time(s) it is opened, only later in the process.

Ref: https://github.com/vectordotdev/vector/issues/16465

To Reproduce Steps to reproduce the behavior:

  1. Configure vector to enable the API
  2. Start vector running in one terminal
  3. Start vector top in another
  4. Observe that it doesn't respond for almost two minutes

Expected behavior The same almost instant startup that happens on Linux and MacOS.

OS WSL2 under Windows

Terminal/Console Windows Terminal

Would it make sense to store the opened file handle for /dev/tty in a OnceCell and then reuse it for subsequent calls to size? If you agree with that path, I can work up a PR to make that happen.

jblang commented 1 year ago

Closing the loop with new findings I reported the vector issue that spawned this one: I've confirmed with co-workers that the issue occurs on both Mac and Linux in addition to WSL2 as the client OS (or when running Vector directly from Windows cmd.exe), so I don't think this is an OS-specific problem.