Skip to content

Commit 7b8e774

Browse files
authored
Merge pull request #21 from nuclearcat/fix-409
upload: Add delay before giving 409 error on upload conflict
2 parents 93e6259 + 53162ec commit 7b8e774

1 file changed

Lines changed: 16 additions & 4 deletions

File tree

src/main.rs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -601,13 +601,25 @@ async fn ax_post_file(
601601
let hdr_content_type = headers.get("Content-Type-Upstream");
602602
let semaphore = get_or_create_semaphore(&state.file_locks, &full_path).await;
603603

604-
// Try to acquire permit - fails immediately if upload in progress
605-
let _permit = match semaphore.try_acquire() {
606-
Ok(permit) => permit,
604+
// Try to acquire permit - wait for up to 30 seconds
605+
let _permit = match tokio::time::timeout(
606+
tokio::time::Duration::from_secs(30),
607+
semaphore.acquire(),
608+
)
609+
.await
610+
{
611+
Ok(Ok(permit)) => permit,
612+
Ok(Err(_)) => {
613+
upload_result = Some((
614+
StatusCode::INTERNAL_SERVER_ERROR,
615+
"Semaphore closed".to_string().into_bytes(),
616+
));
617+
break;
618+
}
607619
Err(_) => {
608620
upload_result = Some((
609621
StatusCode::CONFLICT,
610-
"Upload already in progress".to_string().into_bytes(),
622+
"Timeout waiting for upload".to_string().into_bytes(),
611623
));
612624
break;
613625
}

0 commit comments

Comments
 (0)