From 53d16fd39e83f12369cf7fa5685c39c7c986b931 Mon Sep 17 00:00:00 2001 From: Max Inden Date: Wed, 17 Aug 2022 15:11:11 +0900 Subject: [PATCH 1/4] clippy.toml: Create and disallow unbounded channels When using channels (e.g. `futures::channel::mpsc` or `std::sync::mpsc`) always use the bounded variant, never use the unbounded variant. When using a bounded channel, a slow consumer eventually slows down a fast producer once the channel bound is reached, ideally granting the slow consumer more system resources e.g. CPU time, keeping queues small and thus latencies low. When using an unbounded channel a fast producer continues being a fast producer, growing the channel buffer indefinitely, increasing latency until the illusion of unboundedness breaks and the system runs out of memory. One may use an unbounded channel if one enforces backpressure through an out-of-band mechanism, e.g. the consumer granting the producer send-tokens through a side-channel. See also https://github.com/libp2p/rust-libp2p/pull/2780#discussion_r931988617 --- clippy.toml | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 clippy.toml diff --git a/clippy.toml b/clippy.toml new file mode 100644 index 00000000000..64fa13834d5 --- /dev/null +++ b/clippy.toml @@ -0,0 +1,3 @@ +disallowed-methods = [ + { path = "futures::sync::mpsc::channel", reason = "does not enforce backpressure" }, +] From 208cafb82fe3b7307bf59983baec344b24def336 Mon Sep 17 00:00:00 2001 From: Max Inden Date: Wed, 17 Aug 2022 15:17:20 +0900 Subject: [PATCH 2/4] clippy.toml: Fix import --- clippy.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy.toml b/clippy.toml index 64fa13834d5..f66cc0ac2da 100644 --- a/clippy.toml +++ b/clippy.toml @@ -1,3 +1,3 @@ disallowed-methods = [ - { path = "futures::sync::mpsc::channel", reason = "does not enforce backpressure" }, + { path = "futures::channel::mpsc::unbounded", reason = "does not enforce backpressure" }, ] From ac3535e6b8bf29c00ebf96e061e25b88f365abaf Mon Sep 17 00:00:00 2001 From: Max Inden Date: Wed, 17 Aug 2022 15:17:50 +0900 Subject: [PATCH 3/4] clippy.toml: Test --- clippy.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy.toml b/clippy.toml index f66cc0ac2da..ead1176285d 100644 --- a/clippy.toml +++ b/clippy.toml @@ -1,3 +1,3 @@ disallowed-methods = [ - { path = "futures::channel::mpsc::unbounded", reason = "does not enforce backpressure" }, + { path = "futures::channel::mpsc::channel", reason = "does not enforce backpressure" }, ] From 11fb7f1436d307456bf257eff99c1fd33c65d82e Mon Sep 17 00:00:00 2001 From: Max Inden Date: Wed, 17 Aug 2022 15:27:09 +0900 Subject: [PATCH 4/4] Revert "clippy.toml: Test" This reverts commit ac3535e6b8bf29c00ebf96e061e25b88f365abaf. --- clippy.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy.toml b/clippy.toml index ead1176285d..f66cc0ac2da 100644 --- a/clippy.toml +++ b/clippy.toml @@ -1,3 +1,3 @@ disallowed-methods = [ - { path = "futures::channel::mpsc::channel", reason = "does not enforce backpressure" }, + { path = "futures::channel::mpsc::unbounded", reason = "does not enforce backpressure" }, ]