Skip to content

fix: limit excessive amount of small DATA frames - #935

Merged
seanmonstar merged 1 commit into
masterfrom
sean/tsztlmyvmwkn
Aug 17, 2026
Merged

fix: limit excessive amount of small DATA frames#935
seanmonstar merged 1 commit into
masterfrom
sean/tsztlmyvmwkn

Conversation

@seanmonstar

Copy link
Copy Markdown
Member

HTTP/2 flow control limits DATA payload bytes, but it does not limit the number of frames carrying those bytes. A peer could fragment data into many tiny frames, causing disproportionate memory usage from queued events and slab entries while remaining within the flow-control windows.

To fix it, this adds a connection-level budget for DATA framing overhead. Small frames consume budget according to the difference between their payload length and the approximate cost of a buffered event. Larger frames replenish the budget, up to its original limit. When the application consumes a queued small frame, its buffering charge is also returned.

Non-final DATA frames with an empty decoded payload are discarded after their flow-control accounting is handled. Because they are never exposed to the application, their budget is not returned. Exhausting the budget closes the connection with ENHANCE_YOUR_CALM.

HTTP/2 flow control limits DATA payload bytes, but it does not limit the
number of frames carrying those bytes. A peer could fragment data into many
tiny frames, causing disproportionate memory usage from queued events and
slab entries while remaining within the flow-control windows.

Track a connection-level budget for DATA framing overhead. Small frames
consume budget according to the difference between their payload length and
the approximate cost of a buffered event. Larger frames replenish the budget,
up to its original limit. When the application consumes a queued small frame,
its buffering charge is also returned.

Non-final DATA frames with an empty decoded payload are discarded after their
flow-control accounting is handled. Because they are never exposed to the
application, their budget is not returned. Exhausting the budget closes the
connection with ENHANCE_YOUR_CALM.

This bounds excessive fragmentation retained within h2 while allowing
long-lived connections carrying promptly consumed small messages.
@seanmonstar
seanmonstar merged commit 193833e into master Aug 17, 2026
6 checks passed
@seanmonstar
seanmonstar deleted the sean/tsztlmyvmwkn branch August 17, 2026 12:30
Sruhvx-jpg added a commit to Sruhvx-jpg/h2 that referenced this pull request Aug 23, 2026
Problem

HTTP/2 flow control limits DATA payload bytes, but not the framing overhead
from excessive numbers of small frames. A peer could fragment data into many
tiny frames, causing disproportionate memory usage from queued events while
remaining within flow-control windows.

Solution

Backport the framing overhead budget and empty frame handling from master
(hyperium#935, hyperium#940, hyperium#942, hyperium#945, hyperium#946) to the 0.3.x maintenance branch.

Validation

Ran the full test suite and added regression integration tests in stream_states.rs.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant