2
0
Fork 0
mirror of https://git.asonix.dog/asonix/pict-rs synced 2024-11-20 11:21:14 +00:00

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")]
Timeout(#[from] crate::stream::TimeoutError),
#[error("Client took too long to send request")]
AggregateTimeout,
#[error("Failed external validation")]
ExternalValidation,
}
@ -171,7 +174,8 @@ impl ResponseError for Error {
))
| UploadError::Repo(crate::repo::RepoError::AlreadyClaimed)
| UploadError::UnsupportedProcessExtension
| UploadError::SilentVideoDisabled,
| UploadError::SilentVideoDisabled
| UploadError::AggregateTimeout,
) => 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,

View file

@ -63,9 +63,11 @@ where
R: FullRepo + 'static,
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");
let (input_type, validated_reader) =