rust.large_response_memory
Stability
High
Detects loading entire HTTP responses into memory without streaming.
Why It Matters
Section titled “Why It Matters”Large responses in memory:
- OOM risk — Unbounded response sizes crash servers
- High latency — Must wait for entire download
- Memory pressure — Affects other requests
Example
Section titled “Example”// ❌ 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(())}What Unfault Detects
Section titled “What Unfault Detects”- response.bytes() on unbounded responses
- response.text() for large payloads
- Missing content-length checks
Auto-Fix
Section titled “Auto-Fix”Unfault can add streaming patterns or size limits.