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

Ban uses of Instant operations that can panic #1456

Merged
merged 3 commits into from
Feb 1, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 6 additions & 1 deletion .clippy.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,9 @@ disallowed-methods = [
# see https://github.com/rust-lang/rust/issues/90308 for details.
"std::env::set_var",
"std::env::remove_var",
]

# Avoid instances of https://github.com/rust-lang/rust/issues/86470
"std::time::Instant::duration_since",
"std::time::Instant::elapsed",
"std::time::Instant::sub",
olix0r marked this conversation as resolved.
Show resolved Hide resolved
]
2 changes: 1 addition & 1 deletion linkerd/app/integration/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ macro_rules! assert_eventually {
} else if i == $retries {
panic!(
"assertion failed after {} (retried {} times): {}",
crate::HumanDuration(start_t.elapsed()),
crate::HumanDuration(Instant::now().saturating_duration_since(start_t)),
i,
format_args!($($arg)+)
)
Expand Down
2 changes: 1 addition & 1 deletion linkerd/app/integration/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ impl MetricMatch {
"{}\n retried {} times ({:?})",
e,
MAX_RETRIES,
start_t.elapsed()
Instant::now().saturating_duration_since(start_t)
),
Err(_) => {
tracing::trace!("waiting...");
Expand Down
2 changes: 1 addition & 1 deletion linkerd/detect/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ where
let mut buf = BytesMut::with_capacity(capacity);
let detected = match time::timeout(timeout, detect.detect(&mut io, &mut buf)).await {
Ok(Ok(protocol)) => {
debug!(?protocol, elapsed = ?t0.elapsed(), "DetectResult");
debug!(?protocol, elapsed = ?time::Instant::now().saturating_duration_since(t0), "DetectResult");
Ok(protocol)
}
Err(_) => Err(DetectTimeoutError(timeout, std::marker::PhantomData)),
Expand Down
2 changes: 1 addition & 1 deletion linkerd/http-access-log/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ where

let response: http::Response<B2> = match this.inner.try_poll(cx) {
Poll::Pending => {
data.processing += Instant::now().duration_since(poll_start);
data.processing += Instant::now().saturating_duration_since(poll_start);
return Poll::Pending;
}
Poll::Ready(Err(e)) => return Poll::Ready(Err(e)),
Expand Down