File tree Expand file tree Collapse file tree 2 files changed +11
-6
lines changed Expand file tree Collapse file tree 2 files changed +11
-6
lines changed Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ use tokio::sync::{
1212 mpsc:: { unbounded_channel, UnboundedSender } ,
1313 oneshot,
1414} ;
15+ use tokio:: task;
1516
1617use self :: {
1718 ctrl:: { CtrlTask , Event , ExecuteParam } ,
@@ -72,8 +73,9 @@ impl ModuleExecutor {
7273 let ( stop_sender, stop_receiver) = oneshot:: channel ( ) ;
7374 self . event_sender = Some ( event_sender. clone ( ) ) ;
7475 self . stop_receiver = Some ( stop_receiver) ;
75-
76- tokio:: spawn ( async move {
76+ // avoid coop budget consumed to zero cause hang risk
77+ // related to https://tokio.rs/blog/2020-04-preemption
78+ tokio:: spawn ( task:: unconstrained ( async move {
7779 let _ = run_task_loop_with_event (
7880 & mut ctx,
7981 vec ! [ Box :: new( CtrlTask :: new( event_receiver) ) ] ,
@@ -89,7 +91,7 @@ impl ModuleExecutor {
8991 stop_sender
9092 . send ( ctx. transform_to_make_artifact ( ) )
9193 . expect ( "should success" ) ;
92- } ) ;
94+ } ) ) ;
9395 }
9496
9597 pub async fn hook_after_finish_modules ( & mut self , compilation : & mut Compilation ) {
Original file line number Diff line number Diff line change @@ -10,7 +10,10 @@ use std::{
1010
1111use rspack_error:: Result ;
1212use rspack_util:: ext:: AsAny ;
13- use tokio:: sync:: mpsc:: { self , error:: TryRecvError } ;
13+ use tokio:: {
14+ sync:: mpsc:: { self , error:: TryRecvError } ,
15+ task,
16+ } ;
1417
1518/// Result returned by task
1619///
@@ -81,12 +84,12 @@ pub async fn run_task_loop_with_event<Ctx: 'static>(
8184 let tx = tx. clone ( ) ;
8285 let is_expected_shutdown = is_expected_shutdown. clone ( ) ;
8386 active_task_count += 1 ;
84- tokio:: spawn ( async move {
87+ tokio:: spawn ( task :: unconstrained ( async move {
8588 let r = task. background_run ( ) . await ;
8689 if !is_expected_shutdown. load ( Ordering :: Relaxed ) {
8790 tx. send ( r) . expect ( "failed to send error message" ) ;
8891 }
89- } ) ;
92+ } ) ) ;
9093 }
9194 TaskType :: Sync => {
9295 // merge sync task result directly
You can’t perform that action at this time.
0 commit comments