Skip to content

Commit

Permalink
fix: sending a result should be best effort (filecoin-project#42)
Browse files Browse the repository at this point in the history
The threadpool is used for asynchronous tasks. Due to errors it can
happen that the result is no longer needed. Instead of panicking when
there's no receiving end anymore, only log a message.

Concretely this happens in `bellperson`, where we run the multiexp
operation in parallel on the GPU and the CPU. If there is an error
on the GPU part, we also discard the CPU part. We don't wait for the
CPU operations to be finished, but return early. Hence the receiving
will not be available anymore.
  • Loading branch information
vmx authored Dec 1, 2022
1 parent 0943776 commit 1c7c0ee
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions ec-gpu-gen/src/threadpool.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
//! An interface for dealing with the kinds of parallel computations involved.
use std::env;

use crossbeam_channel::{bounded, Receiver};
use crossbeam_channel::{bounded, Receiver, SendError};
use log::trace;
use once_cell::sync::Lazy;
use yastl::Pool;

Expand Down Expand Up @@ -55,7 +56,13 @@ impl Worker {

THREAD_POOL.spawn(move || {
let res = f();
sender.send(res).unwrap();
// Best effort. We run it in a separate thread, so the receiver might not exist
// anymore, but that's OK. It only means that we are not interested in the result.
// A message is logged though, as concurrency issues are hard to debug and this might
// help in such cases.
if let Err(SendError(_)) = sender.send(res) {
trace!("Cannot send result");
}
});

Waiter { receiver }
Expand Down

0 comments on commit 1c7c0ee

Please sign in to comment.