crossterm-rs / crossterm

Cross platform terminal library rust
MIT License
3.28k stars 281 forks source link

`crossterm::event::poll` function fails on macOS with a timeout larger than 100 million seconds #868

Open overhacked opened 8 months ago

overhacked commented 8 months ago

Describe the bug On macOS[^1], the crossterm::event::poll function fails when a timeout larger than 100 million seconds is specified. The error returned is not helpful in resolving the issue:

Error: Os { code: 22, kind: InvalidInput, message: "Invalid argument" }

This happens because macOS's select(2) syscall:

  1. Accepts a timeval whose tv_sec field is a time_t, which on 64-bit macOS is an int64_t
  2. Returns EINVAL for timeval->tv_sec greater than 100,000,000.

Calling poll() with a very large duration is clearly a misuse of the poll/read() API but it might be nice to make the error message more ergonomic. Absolutely no hard feelings if this is EWONTFIX, though.

[^1]: All versions, as far as I know.

To Reproduce

let _ = crossterm::event::poll(std::time::Duration::MAX).unwrap();

The maximum value of tv_sec was confirmed using this very sloppy C code.

Expected behavior Crossterm could handle this edge case and produce an error message that helps the developer. For example, there was much confusion and discussion when it was encountered in https://github.com/altsem/gitu/issues/22.

OS macOS (all versions AFAIK)

Terminal/Console n/a