mirror of
https://git.asonix.dog/asonix/pict-rs.git
synced 2024-11-24 10:31:07 +00:00
Add AggregateTimeout, don't aggregate with permit
This commit is contained in:
parent
081f5da1fe
commit
2523b6644b
2 changed files with 10 additions and 4 deletions
|
@ -150,6 +150,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")]
|
||||
FailedExternalValidation,
|
||||
}
|
||||
|
@ -183,7 +186,7 @@ impl UploadError {
|
|||
Self::PushJob(_) => ErrorCode::PUSH_JOB,
|
||||
Self::Range => ErrorCode::RANGE_NOT_SATISFIABLE,
|
||||
Self::Limit(_) => ErrorCode::VALIDATE_FILE_SIZE,
|
||||
Self::Timeout(_) => ErrorCode::STREAM_TOO_SLOW,
|
||||
Self::Timeout(_) | Self::AggregateTimeout => ErrorCode::STREAM_TOO_SLOW,
|
||||
Self::FailedExternalValidation => ErrorCode::FAILED_EXTERNAL_VALIDATION,
|
||||
}
|
||||
}
|
||||
|
@ -233,7 +236,8 @@ impl ResponseError for Error {
|
|||
| UploadError::Validation(_)
|
||||
| UploadError::UnsupportedProcessExtension
|
||||
| UploadError::ReadOnly
|
||||
| UploadError::FailedExternalValidation,
|
||||
| UploadError::FailedExternalValidation
|
||||
| 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,
|
||||
|
|
|
@ -55,9 +55,11 @@ async fn process_ingest<S>(
|
|||
where
|
||||
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?;
|
||||
|
||||
let prescribed = Validations {
|
||||
image: &media.image,
|
||||
|
|
Loading…
Reference in a new issue