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

Add check for invalid start and end times for TimeSpan #10349

Merged
merged 2 commits into from Jul 14, 2020

Conversation

gshuflin
Copy link
Contributor

Problem

We noticed a Rust panic that stemmed from trying to subtract a laterstd::time::Duration from an earlier one in some of the concrete_time code used in the workunit store.

Solution

Replace the panic-capable subtraction with a checked subtraction that will log a warning when this happens and create a duration of zero-length, rather than failing.

Copy link
Contributor

@Eric-Arellano Eric-Arellano left a comment

Choose a reason for hiding this comment

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

Thanks!

let duration = match end.checked_sub(start) {
Some(d) => d,
None => {
log::warn!("Invalid TimeSpan - start: {:?}, end: {:?}", start, end);
Copy link
Sponsor Member

@stuhood stuhood Jul 14, 2020

Choose a reason for hiding this comment

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

If this is happening fairly often, we're not going to want to be logging warnings, probably. But it would also be good to track down which codepath is creating inverted ranges like this. So maybe drop to debug...?

It should also be easy to detect that this is happening due to zero-length workunits.

@gshuflin gshuflin merged commit c011bc0 into pantsbuild:master Jul 14, 2020
Eric-Arellano pushed a commit to Eric-Arellano/pants that referenced this pull request Jul 15, 2020
### Problem

We noticed a Rust panic that stemmed from trying to subtract a later`std::time::Duration` from an earlier one in some of the `concrete_time` code used in the workunit store.
 
### Solution

Replace the panic-capable subtraction with a checked subtraction that will log a warning when this happens and create a duration of zero-length, rather than failing.

Note that the bulk of this code was inadvertently merged along with ee0cba3 . This commit contains one minor fix that should've been included with the former code.
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.

None yet

3 participants