From e72ee2823261c4a08dfd4133963ae6161b6f7ff9 Mon Sep 17 00:00:00 2001 From: Andrew Date: Wed, 17 Jun 2020 00:58:23 -0700 Subject: [PATCH] Enforce HW_BUFFER_SIZE inside h1::dispatcher (#1550) --- CHANGES.md | 6 ++++++ actix-http/src/h1/dispatcher.rs | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 739f1b13c..3b4b8dc0b 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,11 @@ # Changes +## [Unreleased] + +### Changed + +* Fix actix_http::h1::dispatcher so it returns when HW_BUFFER_SIZE is reached. Should reduce peak memory consumption during large uploads. [#1550] + ## [3.0.0-alpha.3] - 2020-05-21 ### Added diff --git a/actix-http/src/h1/dispatcher.rs b/actix-http/src/h1/dispatcher.rs index e16d3536f..51f107efb 100644 --- a/actix-http/src/h1/dispatcher.rs +++ b/actix-http/src/h1/dispatcher.rs @@ -861,7 +861,14 @@ where T: AsyncRead + Unpin, { let mut read_some = false; + loop { + // If buf is full return but do not disconnect since + // there is more reading to be done + if buf.len() >= HW_BUFFER_SIZE { + return Ok(Some(false)); + } + let remaining = buf.capacity() - buf.len(); if remaining < LW_BUFFER_SIZE { buf.reserve(HW_BUFFER_SIZE - remaining);