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

Added a forced shutdown on tokio runtimes as the STDIN blocks the shu… #4107

Merged
merged 5 commits into from
Jul 26, 2023
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Linting fixes
  • Loading branch information
john-sharratt committed Jul 26, 2023
commit 218e7d85ec1ebafd6cda679e42058749c29682e9
23 changes: 13 additions & 10 deletions lib/wasix/src/runtime/task_manager/tokio.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::{num::NonZeroUsize, pin::Pin, sync::Arc, time::Duration};
use std::sync::Mutex;
use std::{num::NonZeroUsize, pin::Pin, sync::Arc, time::Duration};

use futures::{future::BoxFuture, Future};
use tokio::runtime::{Handle, Runtime};
@@ -13,24 +13,25 @@ pub enum RuntimeOrHandle {
Handle(Handle),
Runtime(Handle, Arc<Mutex<Option<Runtime>>>),
}
impl From<Handle>
for RuntimeOrHandle {
impl From<Handle> for RuntimeOrHandle {
fn from(value: Handle) -> Self {
Self::Handle(value)
}
}
impl From<Runtime>
for RuntimeOrHandle {
impl From<Runtime> for RuntimeOrHandle {
fn from(value: Runtime) -> Self {
Self::Runtime(value.handle().clone(), Arc::new(Mutex::new(Some(value))))
}
}

impl Drop
for RuntimeOrHandle {
impl Drop for RuntimeOrHandle {
fn drop(&mut self) {
if let Self::Runtime(_, runtime) = self {
runtime.lock().unwrap().take().map(|h| h.shutdown_timeout(Duration::from_secs(0)));
runtime
.lock()
.unwrap()
.take()
.map(|h| h.shutdown_timeout(Duration::from_secs(0)));
}
}
}
@@ -39,7 +40,7 @@ impl RuntimeOrHandle {
pub fn handle(&self) -> &Handle {
match self {
Self::Handle(h) => h,
Self::Runtime(h, _) => h
Self::Runtime(h, _) => h,
}
}
}
@@ -53,7 +54,9 @@ pub struct TokioTaskManager {

impl TokioTaskManager {
pub fn new<I>(rt: I) -> Self
where I: Into<RuntimeOrHandle> {
where
I: Into<RuntimeOrHandle>,
{
let concurrency = std::thread::available_parallelism()
.unwrap_or(NonZeroUsize::new(1).unwrap())
.get();