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

Clamp long timeouts (like Duration::MAX) #208

Merged
merged 11 commits into from
Aug 5, 2024

Conversation

sirhcel
Copy link
Contributor

@sirhcel sirhcel commented Jul 31, 2024

This PR fixes #207 by clamping long timeouts to the capabilities of the underlying platform. Thin preserves monoticity for for the conversion of Duration values and does not expose the details of the conversion methods previously used for the different platforms like:

  • Panics from overflows
  • Non-monotonic actual timeouts duo to cutting off higher bits/modulo operations from casts
  • Unexpected errors when opening ports or reading data

This is especially unpleasant as we are currently recommending using Duration::MAX as "no timeout" (#12).

In theory, this trades accuracy of long timeouts in. In practice, long timeouts already exhibited unexpected and faulty behavior from returning error to panicking due to arithmetic overflows.

It looks like no platform uses an actual timeout data type smaller than i32. So even in combination with expressing timeouts as milliseconds, this gives about 24 days for which timeouts could be expressed accurately. Everything beyond can likely be handled witch lesser precision and spurious timeouts.

@sirhcel sirhcel changed the title Fix large read timeouts (like Duration::MAX) Clamp long timeouts (like Duration::MAX) Aug 1, 2024
They bubbled up when locally using rust-analyzer and Clippy 1.80.
This prepares unit-testing them.
@sirhcel sirhcel force-pushed the fix-read-timeout-max branch 2 times, most recently from b409430 to 1517bca Compare August 2, 2024 17:40
@sirhcel sirhcel marked this pull request as ready for review August 2, 2024 20:35
Copy link
Contributor

@eldruin eldruin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very thorough. Thank you!

@eldruin eldruin merged commit 4bcb745 into serialport:main Aug 5, 2024
30 checks passed
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

Successfully merging this pull request may close these issues.

SerialPortBuilder.timeout(Duration::MAX) gives "Invalid argument"
2 participants