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

fix(sentry-types): Switch to checked version of from_secs_f64 #554

Merged
merged 5 commits into from Feb 24, 2023

Conversation

olksdr
Copy link
Contributor

@olksdr olksdr commented Feb 22, 2023

This change make use of try_from_secs_f64 (the checked version of from_secs_f64), avoiding panics if the incoming seconds is negative, overflows Duration or not finite.

Only one gotcha here, is that this function was added only in rust 1.66.0, which is above current MSRV.

This change make use of `try_from_secs_f64` (the checked version of `from_secs_f64`),
avoding panics if the incoming seconds is negative, overflows Duration or not finite.

Only one gotcha here, is that this function was added only in rust
`1.66.0`, which is above current MSRV.
@olksdr olksdr requested a review from Swatinem February 22, 2023 12:02
@olksdr olksdr self-assigned this Feb 22, 2023
@codecov
Copy link

codecov bot commented Feb 22, 2023

Codecov Report

Merging #554 (d60da03) into master (569b0d9) will increase coverage by 0.03%.
The diff coverage is 100.00%.

❗ Current head d60da03 differs from pull request most recent head 835b5f9. Consider uploading reports for the commit 835b5f9 to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #554      +/-   ##
==========================================
+ Coverage   70.59%   70.62%   +0.03%     
==========================================
  Files          66       66              
  Lines        6658     6665       +7     
==========================================
+ Hits         4700     4707       +7     
  Misses       1958     1958              

@Swatinem
Copy link
Member

Only one gotcha here, is that this function was added only in rust 1.66.0, which is above current MSRV.

I’m surprised that CI does not complain though, its using 1.60

@kamilogorek
Copy link
Contributor

It was stabilized in 1.66, not added, so I wonder if we have incorrect compilation flags set somewhere

@olksdr
Copy link
Contributor Author

olksdr commented Feb 23, 2023

It was stabilized in 1.66, not added, so I wonder if we have incorrect compilation flags set somewhere

That's what I meant 😅 thanks!

How do you want to proceed with this? Maybe change the implementation a bit and for now just use previous function with additional checks on top of it to avoid panics?
There maybe other places where the the call to this function must be changed.

Since this one caused an incident for us getsentry/relay#1872

@kamilogorek
Copy link
Contributor

Welp, MSRV CI was broken - #555
Note that this PR #549 also broke MSRV and it's now 1.65 😅

Before converting an intoming `f64` to `Duration` using `from_secs_f64`,
check if if the value fits into `Duration` type and the function won't
panic.

Starting from Rust `1.66.0` it is possible to use `Duration::try_from_secs_f64`
which returns Option and does not panic.
@olksdr
Copy link
Contributor Author

olksdr commented Feb 23, 2023

How about fix from c987539 which does not use the new function, but just has additional checks in-place to make sure we do not panic.

@kamilogorek
Copy link
Contributor

@olksdr feel free to revert it back to your original fix, we bumped MSRV :)

@olksdr olksdr merged commit 5294125 into master Feb 24, 2023
@olksdr olksdr deleted the fix/do-not-panic-with-negative-duration branch February 24, 2023 09:52
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