Smithay / calloop

A callback-based Event Loop
MIT License
176 stars 34 forks source link

Prevent panics on overflow in timer #121

Closed notgull closed 1 year ago

notgull commented 1 year ago

In master, there is a panic that happens when a large Duration is passed into a Timer. For instance:

let _ = Timer::from_duration(Duration::MAX);

creates this panic:

thread 'sources::timer::tests::no_overflow' panicked at 'overflow when adding duration to instant', library/std/src/time.rs:408:9

This PR fixes this panic such that, instead of causing a panic with large durations, it instead makes sure the timer never goes off. This fix is also applied to TimeoutFuture.

codecov[bot] commented 1 year ago

Codecov Report

Base: 88.71% // Head: 89.11% // Increases project coverage by +0.40% :tada:

Coverage data is based on head (88d5230) compared to base (80819fa). Patch coverage: 82.97% of modified lines in pull request are covered.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #121 +/- ## ========================================== + Coverage 88.71% 89.11% +0.40% ========================================== Files 14 17 +3 Lines 1444 1736 +292 ========================================== + Hits 1281 1547 +266 - Misses 163 189 +26 ``` | Flag | Coverage Δ | | |---|---|---| | macos-latest | `88.60% <82.97%> (-0.12%)` | :arrow_down: | | ubuntu-latest | `87.41% <82.97%> (?)` | | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Smithay#carryforward-flags-in-the-pull-request-comment) to find out more. | [Impacted Files](https://codecov.io/gh/Smithay/calloop/pull/121?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Smithay) | Coverage Δ | | |---|---|---| | [src/sources/timer.rs](https://codecov.io/gh/Smithay/calloop/pull/121/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Smithay#diff-c3JjL3NvdXJjZXMvdGltZXIucnM=) | `86.53% <82.97%> (-1.61%)` | :arrow_down: | | [src/sources/signals.rs](https://codecov.io/gh/Smithay/calloop/pull/121/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Smithay#diff-c3JjL3NvdXJjZXMvc2lnbmFscy5ycw==) | `80.23% <0.00%> (ø)` | | | [src/sys/epoll.rs](https://codecov.io/gh/Smithay/calloop/pull/121/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Smithay#diff-c3JjL3N5cy9lcG9sbC5ycw==) | `98.14% <0.00%> (ø)` | | | [src/sources/ping/eventfd.rs](https://codecov.io/gh/Smithay/calloop/pull/121/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Smithay#diff-c3JjL3NvdXJjZXMvcGluZy9ldmVudGZkLnJz) | `92.20% <0.00%> (ø)` | | | [src/sys/mod.rs](https://codecov.io/gh/Smithay/calloop/pull/121/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Smithay#diff-c3JjL3N5cy9tb2QucnM=) | `91.59% <0.00%> (+0.84%)` | :arrow_up: | | [src/error.rs](https://codecov.io/gh/Smithay/calloop/pull/121/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Smithay#diff-c3JjL2Vycm9yLnJz) | `33.33% <0.00%> (+33.33%)` | :arrow_up: | Help us with your feedback. Take ten seconds to tell us [how you rate us](https://about.codecov.io/nps?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Smithay). Have a feature suggestion? [Share it here.](https://app.codecov.io/gh/feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Smithay)

:umbrella: View full report at Codecov.
:loudspeaker: Do you have feedback about the report comment? Let us know in this issue.