Skip to content

rust.large_response_memory

Stability High

Detects loading entire HTTP responses into memory without streaming.

Large responses in memory:

  • OOM risk — Unbounded response sizes crash servers
  • High latency — Must wait for entire download
  • Memory pressure — Affects other requests
// ❌ Before (entire response in memory)
async fn download_file(url: &str) -> Bytes {
let response = client.get(url).send().await?;
response.bytes().await? // Entire file in RAM!
}
// ✅ After (streaming response)
use tokio::io::AsyncWriteExt;
use futures::StreamExt;
async fn download_file(url: &str, path: &Path) -> Result<()> {
let response = client.get(url).send().await?;
let mut file = tokio::fs::File::create(path).await?;
let mut stream = response.bytes_stream();
while let Some(chunk) = stream.next().await {
file.write_all(&chunk?).await?;
}
Ok(())
}
  • response.bytes() on unbounded responses
  • response.text() for large payloads
  • Missing content-length checks

Unfault can add streaming patterns or size limits.