diff --git a/actix-files/CHANGES.md b/actix-files/CHANGES.md index afb2d5d20..c89c627f2 100644 --- a/actix-files/CHANGES.md +++ b/actix-files/CHANGES.md @@ -3,6 +3,7 @@ ## Unreleased - Minimum supported Rust version (MSRV) is now 1.75. +- Avoid spawning a thread for each file which does more harm than good ## 0.6.6 diff --git a/actix-files/src/chunked.rs b/actix-files/src/chunked.rs index c6c019038..24f2e32ab 100644 --- a/actix-files/src/chunked.rs +++ b/actix-files/src/chunked.rs @@ -80,22 +80,17 @@ async fn chunked_read_file_callback( ) -> Result<(File, Bytes), Error> { use io::{Read as _, Seek as _}; - let res = actix_web::web::block(move || { - let mut buf = Vec::with_capacity(max_bytes); + let mut buf = Vec::with_capacity(max_bytes); - file.seek(io::SeekFrom::Start(offset))?; + file.seek(io::SeekFrom::Start(offset))?; - let n_bytes = file.by_ref().take(max_bytes as u64).read_to_end(&mut buf)?; + let n_bytes = file.by_ref().take(max_bytes as u64).read_to_end(&mut buf)?; - if n_bytes == 0 { - Err(io::Error::from(io::ErrorKind::UnexpectedEof)) - } else { - Ok((file, Bytes::from(buf))) - } - }) - .await??; - - Ok(res) + if n_bytes == 0 { + Err(Error::from(io::Error::from(io::ErrorKind::UnexpectedEof))) + } else { + Ok((file, Bytes::from(buf))) + } } #[cfg(feature = "experimental-io-uring")]