Skip to content
This repository has been archived by the owner on Dec 17, 2024. It is now read-only.

Commit

Permalink
Report error from submit_file() in shim (#132)
Browse files Browse the repository at this point in the history
If an error occurs during file transfer from VM to node, an error
should be reported from the function to higher level so that the program
and VM can terminate deterministically.
  • Loading branch information
tuommaki authored Mar 11, 2024
1 parent 834bf9d commit b36af63
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions crates/shim/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ impl GRPCClient {

fn submit_file(&mut self, task_id: TaskId, file_path: String) -> Result<[u8; 32]> {
let hasher = Arc::new(Mutex::new(blake3::Hasher::new()));
self.rt.block_on(async {
let res = self.rt.block_on(async {
let stream_hasher = Arc::clone(&hasher);
let outbound = async_stream::stream! {

Expand All @@ -185,26 +185,24 @@ impl GRPCClient {
match file.read(&mut buf).await {
Ok(0) => return,
Ok(n) => {

stream_hasher.lock().await.update(&buf[..n]);
yield FileData{ result: Some(grpc::file_data::Result::Chunk(FileChunk{ data: buf[..n].to_vec() }))};
},
Err(err) => {
println!("failed to read file: {}", err);
yield FileData{ result: Some(grpc::file_data::Result::Error(1))};
break;
}
}
}
};

if let Err(err) = self.client.lock().await.submit_file(Request::new(outbound)).await {
println!("failed to submit file: {}", err);
}
self.client.lock().await.submit_file(Request::new(outbound)).await
});
let hasher = Arc::into_inner(hasher).unwrap().into_inner();
let hash = hasher.finalize().into();
let checksum = hasher.finalize().into();

Ok(hash)
res.map(|_| checksum).map_err(|err| err.into())
}

fn submit_result(&mut self, result: &TaskResult) -> Result<bool> {
Expand Down Expand Up @@ -348,7 +346,13 @@ pub fn run(callback: impl Fn(&Task) -> Result<TaskResult>) -> Result<()> {

let result = callback(&task)?;

let should_continue = client.submit_result(&result)?;
let should_continue = match client.submit_result(&result) {
Ok(res) => res,
Err(err) => {
println!("An error occurs during submit_result {err}");
return Err(err);
}
};
if !should_continue {
break;
}
Expand Down

0 comments on commit b36af63

Please sign in to comment.