October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk4 min

Rust Yamux Receive Buffers and Flow Control: Key Facts

Yamux's flow-control window limits what a peer may send; its receive buffer holds unread data. Learn how update policy, read progress, and transport choice affect backpressure and memory.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

For a Rust Yamux stream, the flow-control window and the receive buffer are related but not interchangeable: the window limits how much the peer may send, while the buffer stores bytes that have arrived but have not yet been read by your application. If you want a slow reader to slow the sender, choose read-driven window updates and keep reads progressing while writes are pending.

How Yamux flow control relates to a receive buffer

Yamux multiplexes independent streams over one reliable, ordered connection. In the Rust yamux crate, a Connection wraps the underlying I/O resource and exposes streams implementing futures::io::AsyncRead and AsyncWrite. Yamux is its own protocol; it is not HTTP/2. The current crate documentation observed here is for version 0.14.1, while APIs and defaults in other Rust implementations may differ.

As an Amazon Associate I earn from qualifying purchases.

Think of the two receive-side concepts as separate controls:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • Flow-control window: the receiver’s sending credit. It determines how far the remote sender may advance before it needs more credit.
  • Receive buffer: local storage for data already received but not yet consumed by application code.

When a receiver processes data, it can advance the allowed offset and grant the sender more credit. In a read-driven policy, application reads drive that progress: if the application stops reading, the remote sender eventually runs out of credit. That is the mechanism by which a slow consumer can apply backpressure upstream. The libp2p Yamux documentation describes flow control through backpressure as a key feature.

Choose when the window is updated

The libp2p wrapper’s behavior makes the update policy consequential. The versioned libp2p-yamux 0.47.0 source documentation distinguishes updates on receipt from updates on read.

Policy Effect on a slow application reader What to account for
Update on read Reading advances credit, so a slow application reader can exert backpressure on the remote sender. Keep polling reads while writes are pending; otherwise, bidirectional streams can deadlock when both peers exhaust their windows.
Update on receive Credit is replenished as data arrives, so slow application reads do not themselves provide stream-level backpressure. Received-but-unread data can accumulate. The implementation documentation warns that the receive buffer can overflow unless its maximum suits the throughput and slow-reader periods the workload must tolerate.

Updating on read is the more direct choice when application consumption should regulate the sender. Updating on receipt may suit a workload that needs credit replenished independently of reads, but it makes an appropriate receive-buffer bound especially important. Neither setting determines every layer’s memory use: decoding, queued streams, and application work queues can also retain data.

Prevent a bidirectional read/write deadlock

Read-driven backpressure has a coordination requirement. If both peers write until their receive windows fill, then wait for those writes to finish before reading, neither peer may make the read progress needed to restore credit. The libp2p-yamux 0.47.0 source explicitly warns about this deadlock scenario.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Structure the application so a blocked write does not stop read polling on the same bidirectional stream. For example, use concurrently progressing read and write futures or tasks, with appropriate coordination for shared state and cancellation. The key is not a particular task layout: reads must remain able to drain inbound data while writes are waiting for peer capacity.

Set limits across the whole receive path

There is no single buffer size established as suitable for every Rust Yamux application. First identify the exact crate and version, then inspect its current configuration API and buffering behavior rather than transferring a setting or default from another wrapper.

The minip2p-yamux 0.4.7 documentation lists 256 KiB as Yamux’s specification-defined initial stream receive window. That is a protocol initial-window figure for that documentation, not a universal Rust implementation default, a recommended application buffer size, or a throughput benchmark.

When tuning, consider aggregate memory as well as per-stream behavior. Many active streams can multiply individually modest allowances. Where the implementation or application exposes controls, bound unread bytes, frame decoding, inbound stream queues, active stream counts, and downstream work queues. Choose limits based on the workload’s tolerated bursts and slow-reader periods; the cited documentation does not establish universal numeric limits for those layers.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Decide whether you need a separate multiplexer

Before configuring Yamux, check the transport. In libp2p, QUIC, WebTransport, and WebRTC are listed as transports with native streams, which may remove the need for an additional muxing layer. The libp2p multiplexing overview describes transport negotiation and native-stream options.

If a separate muxer is required, compare the choices by their receive behavior and compatibility needs:

Option Receive-side behavior When it fits
Yamux, updates on read Application reads can slow the remote sender through flow control. A separate muxer is needed and slow-consumer pressure should reach the sender, with reads kept active during writes.
Yamux, updates on receive Credit replenishes as data arrives, independently of application reads. The desired throughput behavior justifies separately bounding unread receive data.
mplex It provides no flow control, and libp2p documentation says it does not limit the number of peer-opened streams. Primarily a legacy interoperability requirement, not a flow-controlled workload.
Transport-native streams The transport supplies streams, potentially avoiding an extra muxer. A selected transport such as QUIC, WebTransport, or WebRTC already provides the needed stream model.

The libp2p mplex documentation states that mplex does not provide flow control. Your choice should account for native transport streams, whether slow reads should throttle the sender, aggregate memory across concurrent streams, existing-peer compatibility, and whether reads continue while writes are blocked.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Leave a Reply

Your email address will not be published. Required fields are marked *

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.