Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(services/monoiofs): drop JoinHandle in worker thread #5031

Merged
merged 1 commit into from
Aug 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 4 additions & 13 deletions core/src/services/monoiofs/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ use flume::Receiver;
use flume::Sender;
use futures::channel::oneshot;
use futures::Future;
use monoio::task::JoinHandle;
use monoio::FusionDriver;
use monoio::RuntimeBuilder;

Expand Down Expand Up @@ -122,30 +121,22 @@ impl MonoiofsCore {
self.unwrap(rx.await)
}

/// Create a TaskSpawner, send it to the thread pool, spawn the task
/// and return its [`JoinHandle`]. Task panic cannot propagate
/// through the [`JoinHandle`] and should be handled elsewhere.
pub async fn spawn<F, Fut, T>(&self, f: F) -> JoinHandle<T>
/// Create a TaskSpawner, send it to the thread pool and spawn the task.
pub async fn spawn<F, Fut, T>(&self, f: F)
where
F: FnOnce() -> Fut + 'static + Send,
Fut: Future<Output = T>,
T: 'static + Send,
T: 'static,
{
// oneshot channel to send JoinHandle back
let (tx, rx) = oneshot::channel();
let result = self
.tx
.send_async(Box::new(move || {
// task will be spawned on current thread, task panic
// will cause current worker thread panic
let handle = monoio::spawn(async move { f().await });
// discard the result if send failed due to
// MonoiofsCore::spawn cancelled
let _ = tx.send(handle);
monoio::spawn(async move { f().await });
}))
.await;
self.unwrap(result);
self.unwrap(rx.await)
}

/// This method always panics. It is called only when at least a
Expand Down
Loading