Skip to content

Commit

Permalink
test: remove env::set_var call in test logging initialization (#1437)
Browse files Browse the repository at this point in the history
Per rust-lang/rust#90308, this is potentially a data race. In practice,
I don't think it was actually problematic here, but it also wasn't doing
anything of value, so we should remove it.

This is currently the only `env::set_var` or `env::remove_var` call in
the proxy.

To prevent uses of these functions in the future, I also added a 
`disallowed-methods` configuration in `.clippy.toml` to emit a
warning for any uses of `std::env::set_var` and
`std::env::remove_var`. Unfortunately, this required adding a
`deny` attribute basically everywhere, which is why this diff touches
so many files.

Closes linkerd/linkerd2#7651
  • Loading branch information
hawkw authored Jan 20, 2022
1 parent d3cf6a0 commit 8f7be6f
Show file tree
Hide file tree
Showing 60 changed files with 65 additions and 59 deletions.
7 changes: 7 additions & 0 deletions .clippy.toml
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
type-complexity-threshold = 500
disallowed-methods = [
# mutating environment variables in a multi-threaded context can
# cause data races.
# see https://github.com/rust-lang/rust/issues/90308 for details.
"std::env::set_var",
"std::env::remove_var",
]
2 changes: 1 addition & 1 deletion hyper-balance/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![deny(warnings, rust_2018_idioms)]
#![deny(warnings, rust_2018_idioms, clippy::disallowed_method)]
#![forbid(unsafe_code)]

use hyper::body::HttpBody;
Expand Down
2 changes: 1 addition & 1 deletion linkerd/addr/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![deny(warnings, rust_2018_idioms)]
#![deny(warnings, rust_2018_idioms, clippy::disallowed_method)]
#![forbid(unsafe_code)]
use linkerd_dns_name::Name;
use std::{
Expand Down
2 changes: 1 addition & 1 deletion linkerd/app/admin/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![deny(warnings, rust_2018_idioms)]
#![deny(warnings, rust_2018_idioms, clippy::disallowed_method)]
#![forbid(unsafe_code)]

mod server;
Expand Down
2 changes: 1 addition & 1 deletion linkerd/app/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//! - Tap
//! - Metric labeling
#![deny(warnings, rust_2018_idioms)]
#![deny(warnings, rust_2018_idioms, clippy::disallowed_method)]
#![forbid(unsafe_code)]

pub use drain;
Expand Down
2 changes: 1 addition & 1 deletion linkerd/app/gateway/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![deny(warnings, rust_2018_idioms)]
#![deny(warnings, rust_2018_idioms, clippy::disallowed_method)]
#![forbid(unsafe_code)]

mod gateway;
Expand Down
2 changes: 1 addition & 1 deletion linkerd/app/inbound/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//! The inbound proxy is responsible for terminating traffic from other network
//! endpoints inbound to the local application.
#![deny(warnings, rust_2018_idioms)]
#![deny(warnings, rust_2018_idioms, clippy::disallowed_method)]
#![forbid(unsafe_code)]

mod accept;
Expand Down
2 changes: 1 addition & 1 deletion linkerd/app/integration/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Shared infrastructure for integration tests
#![deny(warnings, rust_2018_idioms)]
#![deny(warnings, rust_2018_idioms, clippy::disallowed_method)]
#![forbid(unsafe_code)]

mod test_env;
Expand Down
2 changes: 1 addition & 1 deletion linkerd/app/outbound/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//!
//! The outbound proxy is responsible for routing traffic from the local application to other hosts.
#![deny(warnings, rust_2018_idioms)]
#![deny(warnings, rust_2018_idioms, clippy::disallowed_method)]
#![forbid(unsafe_code)]

mod discover;
Expand Down
2 changes: 1 addition & 1 deletion linkerd/app/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Configures and executes the proxy
#![deny(warnings, rust_2018_idioms)]
#![deny(warnings, rust_2018_idioms, clippy::disallowed_method)]
#![forbid(unsafe_code)]

pub mod dst;
Expand Down
2 changes: 1 addition & 1 deletion linkerd/app/test/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Shared infrastructure for integration tests
#![deny(warnings, rust_2018_idioms)]
#![deny(warnings, rust_2018_idioms, clippy::disallowed_method)]
#![forbid(unsafe_code)]

pub use futures::{future, FutureExt, TryFuture, TryFutureExt};
Expand Down
2 changes: 1 addition & 1 deletion linkerd/cache/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![deny(warnings, rust_2018_idioms)]
#![deny(warnings, rust_2018_idioms, clippy::disallowed_method)]
#![forbid(unsafe_code)]

use linkerd_stack::{layer, NewService};
Expand Down
2 changes: 1 addition & 1 deletion linkerd/conditional/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![deny(warnings, rust_2018_idioms)]
#![deny(warnings, rust_2018_idioms, clippy::disallowed_method)]
#![forbid(unsafe_code)]

/// Like `std::option::Option<C>` but `None` carries a reason why the value
Expand Down
2 changes: 1 addition & 1 deletion linkerd/detect/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![deny(warnings, rust_2018_idioms)]
#![deny(warnings, rust_2018_idioms, clippy::disallowed_method)]
#![forbid(unsafe_code)]

use bytes::BytesMut;
Expand Down
2 changes: 1 addition & 1 deletion linkerd/dns/name/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![deny(warnings, rust_2018_idioms)]
#![deny(warnings, rust_2018_idioms, clippy::disallowed_method)]
#![forbid(unsafe_code)]

mod name;
Expand Down
2 changes: 1 addition & 1 deletion linkerd/dns/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![deny(warnings, rust_2018_idioms)]
#![deny(warnings, rust_2018_idioms, clippy::disallowed_method)]
#![forbid(unsafe_code)]

use linkerd_dns_name::NameRef;
Expand Down
2 changes: 1 addition & 1 deletion linkerd/errno/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![deny(warnings, rust_2018_idioms)]
#![deny(warnings, rust_2018_idioms, clippy::disallowed_method)]
#![forbid(unsafe_code)]

use std::fmt;
Expand Down
2 changes: 1 addition & 1 deletion linkerd/error-respond/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Layer to map service errors into responses.
#![deny(warnings, rust_2018_idioms)]
#![deny(warnings, rust_2018_idioms, clippy::disallowed_method)]
#![forbid(unsafe_code)]

use futures::{ready, TryFuture};
Expand Down
2 changes: 1 addition & 1 deletion linkerd/error/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![deny(warnings, rust_2018_idioms)]
#![deny(warnings, rust_2018_idioms, clippy::disallowed_method)]
#![forbid(unsafe_code)]

pub mod recover;
Expand Down
2 changes: 1 addition & 1 deletion linkerd/exp-backoff/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![deny(warnings, rust_2018_idioms)]
#![deny(warnings, rust_2018_idioms, clippy::disallowed_method)]
#![forbid(unsafe_code)]

use futures::Stream;
Expand Down
2 changes: 1 addition & 1 deletion linkerd/http-box/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![deny(warnings, rust_2018_idioms)]
#![deny(warnings, rust_2018_idioms, clippy::disallowed_method)]
#![forbid(unsafe_code)]

mod body;
Expand Down
2 changes: 1 addition & 1 deletion linkerd/http-classify/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![deny(warnings, rust_2018_idioms)]
#![deny(warnings, rust_2018_idioms, clippy::disallowed_method)]
#![forbid(unsafe_code)]

mod service;
Expand Down
2 changes: 1 addition & 1 deletion linkerd/http-metrics/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![deny(warnings, rust_2018_idioms)]
#![deny(warnings, rust_2018_idioms, clippy::disallowed_method)]
#![forbid(unsafe_code)]

pub use self::{requests::Requests, retries::Retries};
Expand Down
2 changes: 1 addition & 1 deletion linkerd/http-retry/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![deny(warnings, rust_2018_idioms)]
#![deny(warnings, rust_2018_idioms, clippy::disallowed_method)]
#![forbid(unsafe_code)]

use bytes::{Buf, BufMut, Bytes, BytesMut};
Expand Down
2 changes: 1 addition & 1 deletion linkerd/identity/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![deny(warnings, rust_2018_idioms)]
#![deny(warnings, rust_2018_idioms, clippy::disallowed_method)]
#![forbid(unsafe_code)]

mod credentials;
Expand Down
2 changes: 1 addition & 1 deletion linkerd/io/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![deny(warnings, rust_2018_idioms)]
#![deny(warnings, rust_2018_idioms, clippy::disallowed_method)]
#![forbid(unsafe_code)]

mod boxed;
Expand Down
2 changes: 1 addition & 1 deletion linkerd/meshtls/boring/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![deny(warnings, rust_2018_idioms)]
#![deny(warnings, rust_2018_idioms, clippy::disallowed_method)]
#![forbid(unsafe_code)]

//! This crate provides an implementation of _meshtls_ backed by `boringssl` (as
Expand Down
2 changes: 1 addition & 1 deletion linkerd/meshtls/rustls/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![deny(warnings, rust_2018_idioms)]
#![deny(warnings, rust_2018_idioms, clippy::disallowed_method)]
#![forbid(unsafe_code)]

mod client;
Expand Down
2 changes: 1 addition & 1 deletion linkerd/meshtls/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![deny(warnings, rust_2018_idioms)]
#![deny(warnings, rust_2018_idioms, clippy::disallowed_method)]
#![forbid(unsafe_code)]

//! This crate provides a static interface for the proxy's x509 certificate
Expand Down
2 changes: 1 addition & 1 deletion linkerd/meshtls/tests/boring.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#![cfg(feature = "boring")]
#![deny(warnings, rust_2018_idioms)]
#![deny(warnings, rust_2018_idioms, clippy::disallowed_method)]
#![forbid(unsafe_code)]

mod util;
Expand Down
2 changes: 1 addition & 1 deletion linkerd/meshtls/tests/rustls.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#![cfg(feature = "rustls")]
#![deny(warnings, rust_2018_idioms)]
#![deny(warnings, rust_2018_idioms, clippy::disallowed_method)]
#![forbid(unsafe_code)]

mod util;
Expand Down
2 changes: 1 addition & 1 deletion linkerd/metrics/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![deny(warnings, rust_2018_idioms)]
#![deny(warnings, rust_2018_idioms, clippy::disallowed_method)]
#![forbid(unsafe_code)]

//! Utilities for exposing metrics to Prometheus.
Expand Down
2 changes: 1 addition & 1 deletion linkerd/opencensus/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![deny(warnings, rust_2018_idioms)]
#![deny(warnings, rust_2018_idioms, clippy::disallowed_method)]
#![forbid(unsafe_code)]

pub mod metrics;
Expand Down
2 changes: 1 addition & 1 deletion linkerd/proxy/api-resolve/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![deny(warnings, rust_2018_idioms)]
#![deny(warnings, rust_2018_idioms, clippy::disallowed_method)]
#![forbid(unsafe_code)]

use linkerd2_proxy_api as api;
Expand Down
2 changes: 1 addition & 1 deletion linkerd/proxy/core/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![deny(warnings, rust_2018_idioms)]
#![deny(warnings, rust_2018_idioms, clippy::disallowed_method)]
#![forbid(unsafe_code)]

pub mod resolve;
Expand Down
2 changes: 1 addition & 1 deletion linkerd/proxy/discover/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![deny(warnings, rust_2018_idioms)]
#![deny(warnings, rust_2018_idioms, clippy::disallowed_method)]
#![forbid(unsafe_code)]

use linkerd_proxy_core::Resolve;
Expand Down
2 changes: 1 addition & 1 deletion linkerd/proxy/dns-resolve/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![deny(warnings, rust_2018_idioms)]
#![deny(warnings, rust_2018_idioms, clippy::disallowed_method)]
#![forbid(unsafe_code)]

use futures::{future, prelude::*, stream};
Expand Down
2 changes: 1 addition & 1 deletion linkerd/proxy/http/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![deny(warnings, rust_2018_idioms)]
#![deny(warnings, rust_2018_idioms, clippy::disallowed_method)]
#![forbid(unsafe_code)]
use http::header::AsHeaderName;
use http::uri::Authority;
Expand Down
2 changes: 1 addition & 1 deletion linkerd/proxy/identity-client/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![deny(warnings, rust_2018_idioms)]
#![deny(warnings, rust_2018_idioms, clippy::disallowed_method)]
#![forbid(unsafe_code)]

pub mod certify;
Expand Down
2 changes: 1 addition & 1 deletion linkerd/proxy/resolve/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![deny(warnings, rust_2018_idioms)]
#![deny(warnings, rust_2018_idioms, clippy::disallowed_method)]
#![forbid(unsafe_code)]

pub mod map_endpoint;
Expand Down
2 changes: 1 addition & 1 deletion linkerd/proxy/tap/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![deny(warnings, rust_2018_idioms)]
#![deny(warnings, rust_2018_idioms, clippy::disallowed_method)]
#![forbid(unsafe_code)]

use linkerd_tls as tls;
Expand Down
2 changes: 1 addition & 1 deletion linkerd/proxy/tcp/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![deny(warnings, rust_2018_idioms)]
#![deny(warnings, rust_2018_idioms, clippy::disallowed_method)]
#![forbid(unsafe_code)]

pub mod balance;
Expand Down
2 changes: 1 addition & 1 deletion linkerd/reconnect/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! Conditionally reconnects with a pluggable recovery/backoff strategy.
#![deny(warnings, rust_2018_idioms)]
#![deny(warnings, rust_2018_idioms, clippy::disallowed_method)]
#![forbid(unsafe_code)]

#[cfg(test)]
Expand Down
2 changes: 1 addition & 1 deletion linkerd/retry/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![deny(warnings, rust_2018_idioms)]
#![deny(warnings, rust_2018_idioms, clippy::disallowed_method)]
#![forbid(unsafe_code)]

use futures::future;
Expand Down
2 changes: 1 addition & 1 deletion linkerd/server-policy/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![deny(warnings, rust_2018_idioms)]
#![deny(warnings, rust_2018_idioms, clippy::disallowed_method)]
#![forbid(unsafe_code)]

mod network;
Expand Down
2 changes: 1 addition & 1 deletion linkerd/service-profiles/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![deny(warnings, rust_2018_idioms)]
#![deny(warnings, rust_2018_idioms, clippy::disallowed_method)]
#![forbid(unsafe_code)]

use futures::Stream;
Expand Down
2 changes: 1 addition & 1 deletion linkerd/signal/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Unix signal handling for the proxy binary.
#![deny(warnings, rust_2018_idioms)]
#![deny(warnings, rust_2018_idioms, clippy::disallowed_method)]
#![forbid(unsafe_code)]

/// Returns a `Future` that completes when the proxy should start to shutdown.
Expand Down
2 changes: 1 addition & 1 deletion linkerd/stack/metrics/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![deny(warnings, rust_2018_idioms)]
#![deny(warnings, rust_2018_idioms, clippy::disallowed_method)]
#![forbid(unsafe_code)]

mod layer;
Expand Down
2 changes: 1 addition & 1 deletion linkerd/stack/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Utilities for composing Tower Services.
#![deny(warnings, rust_2018_idioms)]
#![deny(warnings, rust_2018_idioms, clippy::disallowed_method)]
#![forbid(unsafe_code)]

mod arc_new_service;
Expand Down
2 changes: 1 addition & 1 deletion linkerd/stack/tracing/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![deny(warnings, rust_2018_idioms)]
#![deny(warnings, rust_2018_idioms, clippy::disallowed_method)]
#![forbid(unsafe_code)]

use linkerd_stack::{layer, NewService, Proxy};
Expand Down
2 changes: 1 addition & 1 deletion linkerd/tls/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![deny(warnings, rust_2018_idioms)]
#![deny(warnings, rust_2018_idioms, clippy::disallowed_method)]
#![forbid(unsafe_code)]

pub mod client;
Expand Down
2 changes: 1 addition & 1 deletion linkerd/tls/test-util/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![deny(warnings, rust_2018_idioms)]
#![deny(warnings, rust_2018_idioms, clippy::disallowed_method)]
#![forbid(unsafe_code)]

pub struct Entity {
Expand Down
2 changes: 1 addition & 1 deletion linkerd/tonic-watch/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![deny(warnings, rust_2018_idioms)]
#![deny(warnings, rust_2018_idioms, clippy::disallowed_method)]
#![forbid(unsafe_code)]

use futures::prelude::*;
Expand Down
2 changes: 1 addition & 1 deletion linkerd/trace-context/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![deny(warnings, rust_2018_idioms)]
#![deny(warnings, rust_2018_idioms, clippy::disallowed_method)]
#![forbid(unsafe_code)]

mod propagation;
Expand Down
2 changes: 1 addition & 1 deletion linkerd/tracing/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![deny(warnings, rust_2018_idioms)]
#![deny(warnings, rust_2018_idioms, clippy::disallowed_method)]
#![forbid(unsafe_code)]

pub mod level;
Expand Down
1 change: 0 additions & 1 deletion linkerd/tracing/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ pub fn trace_subscriber(default: impl ToString) -> (Dispatch, Handle) {
.or_else(|_| env::var("RUST_LOG"))
.unwrap_or_else(|_| default.to_string());
let log_format = env::var("LINKERD2_PROXY_LOG_FORMAT").unwrap_or_else(|_| "PLAIN".to_string());
env::set_var("LINKERD2_PROXY_LOG_FORMAT", &log_format);
// This may fail, since the global log compat layer may have been
// initialized by another test.
let _ = init_log_compat();
Expand Down
2 changes: 1 addition & 1 deletion linkerd/transport-header/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![deny(warnings, rust_2018_idioms)]
#![deny(warnings, rust_2018_idioms, clippy::disallowed_method)]
#![forbid(unsafe_code)]

mod server;
Expand Down
2 changes: 1 addition & 1 deletion linkerd/transport-metrics/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![deny(warnings, rust_2018_idioms)]
#![deny(warnings, rust_2018_idioms, clippy::disallowed_method)]
#![forbid(unsafe_code)]

mod client;
Expand Down
2 changes: 1 addition & 1 deletion linkerd2-proxy/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! The main entrypoint for the proxy.

#![deny(warnings, rust_2018_idioms)]
#![deny(warnings, rust_2018_idioms, clippy::disallowed_method)]
#![forbid(unsafe_code)]

// Emit a compile-time error if no TLS implementations are enabled. When adding
Expand Down
2 changes: 1 addition & 1 deletion opencensus-proto/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//!
//! Vendored from <https://github.com/census-instrumentation/opencensus-proto/>.

#![deny(warnings, rust_2018_idioms)]
#![deny(warnings, rust_2018_idioms, clippy::disallowed_method)]
#![forbid(unsafe_code)]

pub mod agent {
Expand Down

0 comments on commit 8f7be6f

Please sign in to comment.