Skip to content

Commit

Permalink
slightly improved server error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
djugei committed Apr 4, 2024
1 parent 95b3777 commit 92b89c7
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use axum::{
};
use core::future::Future;
use log::{debug, error, info};
use std::{path::PathBuf, sync::Arc};
use std::{panic, path::PathBuf, sync::Arc};
use thiserror::Error;
use tokio::fs::File;

Expand Down Expand Up @@ -187,12 +187,15 @@ where

let file = {
let delta = delta.clone();
let (snd, rcv) = tokio::sync::oneshot::channel();
tokio::spawn(async move {
let f = s.get_or_generate(delta).await;
snd.send(f).expect("request was probably canceled");
});
rcv.await.expect("uncaught error in FileCache, thats a bug")??
// spawning is done here so the generation continues even if the original request times out or is cancled
match tokio::spawn(async move { s.get_or_generate(delta).await })
.await
.map_err(|e| e.try_into_panic())
{
Err(Ok(p)) => panic::resume_unwind(p),
Err(Err(_)) => unreachable!("this task does not get cancled"),
Ok(r) => r??,
}
};

let len = file.metadata().await?.len();
Expand Down

0 comments on commit 92b89c7

Please sign in to comment.