Add AggregateTimeout, don't aggregate with permit

This commit is contained in:
asonix 2023-12-04 15:36:23 -06:00
parent 225599cb50
commit 39de25cbfd
2 changed files with 9 additions and 3 deletions

View File

@ -133,6 +133,9 @@ pub(crate) enum UploadError {
#[error("Response timeout")] #[error("Response timeout")]
Timeout(#[from] crate::stream::TimeoutError), Timeout(#[from] crate::stream::TimeoutError),
#[error("Client took too long to send request")]
AggregateTimeout,
#[error("Failed external validation")] #[error("Failed external validation")]
ExternalValidation, ExternalValidation,
} }
@ -171,7 +174,8 @@ impl ResponseError for Error {
)) ))
| UploadError::Repo(crate::repo::RepoError::AlreadyClaimed) | UploadError::Repo(crate::repo::RepoError::AlreadyClaimed)
| UploadError::UnsupportedProcessExtension | UploadError::UnsupportedProcessExtension
| UploadError::SilentVideoDisabled, | UploadError::SilentVideoDisabled
| UploadError::AggregateTimeout,
) => StatusCode::BAD_REQUEST, ) => StatusCode::BAD_REQUEST,
Some(UploadError::Magick(e)) if e.is_client_error() => StatusCode::BAD_REQUEST, Some(UploadError::Magick(e)) if e.is_client_error() => StatusCode::BAD_REQUEST,
Some(UploadError::Ffmpeg(e)) if e.is_client_error() => StatusCode::BAD_REQUEST, Some(UploadError::Ffmpeg(e)) if e.is_client_error() => StatusCode::BAD_REQUEST,

View File

@ -63,9 +63,11 @@ where
R: FullRepo + 'static, R: FullRepo + 'static,
S: Store, S: Store,
{ {
let permit = crate::PROCESS_SEMAPHORE.acquire().await; let bytes = tokio::time::timeout(Duration::from_secs(60), aggregate(stream))
.await
.map_err(|_| UploadError::AggregateTimeout)??;
let bytes = aggregate(stream).await?; let permit = crate::PROCESS_SEMAPHORE.acquire().await;
tracing::trace!("Validating bytes"); tracing::trace!("Validating bytes");
let (input_type, validated_reader) = let (input_type, validated_reader) =