Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
overhacked opened this issue Mar 5, 2024 · 0 comments

Comments

@overhacked
Copy link

overhacked commented Mar 5, 2024

Describe the bug
On macOS1, 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.

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 altsem/gitu#22.

OS
macOS (all versions AFAIK)

Terminal/Console
n/a

Footnotes

  1. All versions, as far as I know.

@overhacked overhacked changed the title crossterm::event::poll function fails on macOS with a timeout larger than 4_294_967_355u64 seconds crossterm::event::poll function fails on macOS with a timeout larger than 100 million seconds Mar 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant