Skip to content

Memory bloat due to accumulating arbitrarily large response bodies in net (tracking issue) #48894

Open

Description

@freyacodes

During network fetch, the net crate will accumulate the entire response body. This is typically shared by way of Arc<Mutex<...>>. By retaining arbitrarily large response bodies we open up to the consequences of running out of free memory. This is less of a thorough investigation and more of a pattern that I have been noticing.

This is the part that accumulates the response during network fetch:

response_stream
.into_body()
.try_fold(response_body, move |response_body_accumulator, chunk| {
if cancellation_listener.cancelled() {
*response_body_accumulator.lock() = ResponseBody::Done(vec![]);
let _ = done_sender.send(Data::Cancelled);
return future::ready(Err(std::io::Error::new(
std::io::ErrorKind::Interrupted,
"Fetch aborted",
)));
}
if let ResponseBody::Receiving(ref mut body) = *response_body_accumulator.lock() {
body.extend_from_slice(&chunk);
let _ = done_sender.send(Data::Payload(chunk));
}
future::ready(Ok(response_body_accumulator))
})

Below are the parts that I think we need to rein in somehow. Potential ways could be to buffer data to disk, imposing size limits, as well as dropping excess data. This list might not be exhaustive.

Additionally, there is the related issue of adding backpressure to fetch targets when bytes are potentially processed slower than they are provided by fetching:

Activity

  1. added
    C-untriaged
    on Oct 13, 2026
  2. added
    I-perf-bloat
    B-meta
    and removed
    C-untriaged
    on Oct 13, 2026
  3. Lemeri123 commented on Oct 14, 2026

    @Lemeri123

    I am willing to work on this

  4. freyacodes commented on Oct 16, 2026

    @freyacodes
    MemberAuthor

    Hi @Lemeri123

    This is a tracking issue, and not a discrete task that someone could pick up. I suppose you could tackle one of the loosely described tasks, but i would recommend against that for a first issue.

    You might be interested in this guide for finding things to work on: https://book.servo.org/contributing/finding-things-to-do.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-networkB-metaI-perf-bloat

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions