Skip to content

Commit

Permalink
clippy.toml: Create and disallow unbounded channels
Browse files Browse the repository at this point in the history
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
libp2p#2780 (comment)
  • Loading branch information
mxinden committed Aug 17, 2022
1 parent d2c5053 commit 14cd5d6
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions clippy.toml
@@ -0,0 +1,3 @@
disallowed-methods = [
{ path = "futures::sync::mpsc::channel", reason = "does not enforce backpressure" },
]

0 comments on commit 14cd5d6

Please sign in to comment.