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(core): remove hang risk caused by coop budget in tokio #8434

Merged
merged 2 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
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
5 changes: 3 additions & 2 deletions crates/rspack_core/src/compiler/module_executor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use tokio::sync::{
mpsc::{unbounded_channel, UnboundedSender},
oneshot,
};
use tokio::task;

use self::{
ctrl::{CtrlTask, Event, ExecuteParam},
Expand Down Expand Up @@ -73,7 +74,7 @@ impl ModuleExecutor {
self.event_sender = Some(event_sender.clone());
self.stop_receiver = Some(stop_receiver);

tokio::spawn(async move {
tokio::spawn(task::unconstrained(async move {
let _ = run_task_loop_with_event(
&mut ctx,
vec![Box::new(CtrlTask::new(event_receiver))],
Expand All @@ -89,7 +90,7 @@ impl ModuleExecutor {
stop_sender
.send(ctx.transform_to_make_artifact())
.expect("should success");
});
}));
}

pub async fn hook_after_finish_modules(&mut self, compilation: &mut Compilation) {
Expand Down
9 changes: 6 additions & 3 deletions crates/rspack_core/src/utils/task_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ use std::{

use rspack_error::Result;
use rspack_util::ext::AsAny;
use tokio::sync::mpsc::{self, error::TryRecvError};
use tokio::{
sync::mpsc::{self, error::TryRecvError},
task,
};

/// Result returned by task
///
Expand Down Expand Up @@ -81,12 +84,12 @@ pub async fn run_task_loop_with_event<Ctx: 'static>(
let tx = tx.clone();
let is_expected_shutdown = is_expected_shutdown.clone();
active_task_count += 1;
tokio::spawn(async move {
tokio::spawn(task::unconstrained(async move {
let r = task.background_run().await;
if !is_expected_shutdown.load(Ordering::Relaxed) {
tx.send(r).expect("failed to send error message");
}
});
}));
}
TaskType::Sync => {
// merge sync task result directly
Expand Down
Loading