@@ -13,6 +13,7 @@ use crate::host::module_host::{
1313 ViewCallResult , ViewCommand , ViewCommandResult , ViewOutcome ,
1414} ;
1515use crate :: host:: scheduler:: { CallScheduledFunctionResult , ScheduledFunctionParams } ;
16+ use crate :: host:: block_on_scoped;
1617use crate :: host:: {
1718 ArgsTuple , ModuleHost , ProcedureCallError , ProcedureCallResult , ReducerCallError , ReducerCallResult , ReducerId ,
1819 ReducerOutcome , Scheduler , UpdateDatabaseResult ,
@@ -698,7 +699,7 @@ impl<T: WasmInstance> WasmModuleInstance<T> {
698699 if let Some ( prepare_offset) = marker_tx_data. tx_offset ( ) {
699700 if let Some ( mut durable) = stdb. durable_tx_offset ( ) {
700701 let handle = tokio:: runtime:: Handle :: current ( ) ;
701- let _ = handle . block_on ( durable. wait_for ( prepare_offset) ) ;
702+ let _ = block_on_scoped ( & handle , durable. wait_for ( prepare_offset) ) ;
702703 }
703704 }
704705
@@ -725,11 +726,13 @@ impl<T: WasmInstance> WasmModuleInstance<T> {
725726 // Without this, A could delete its coordinator log entry while B's commit
726727 // is still in-memory — a B crash at that point would leave the tx uncommitted
727728 // with no way to recover (A has already forgotten it committed).
728- let handle = tokio:: runtime:: Handle :: current ( ) ;
729729 if let Some ( mut durable) = stdb. durable_tx_offset ( ) {
730- if let Ok ( offset) = handle. block_on ( commit_result. tx_offset ) {
731- let _ = handle. block_on ( durable. wait_for ( offset) ) ;
732- }
730+ let handle = tokio:: runtime:: Handle :: current ( ) ;
731+ block_on_scoped ( & handle, async move {
732+ if let Ok ( offset) = commit_result. tx_offset . await {
733+ let _ = durable. wait_for ( offset) . await ;
734+ }
735+ } ) ;
733736 }
734737
735738 // Notify coordinator that B has committed so it can delete its coordinator log entry.
@@ -738,7 +741,7 @@ impl<T: WasmInstance> WasmModuleInstance<T> {
738741 let router = replica_ctx. call_reducer_router . clone ( ) ;
739742 let client_http = replica_ctx. call_reducer_client . clone ( ) ;
740743 let auth_token = replica_ctx. call_reducer_auth_token . clone ( ) ;
741- handle . spawn ( send_ack_commit_to_coordinator (
744+ tokio :: runtime :: Handle :: current ( ) . spawn ( send_ack_commit_to_coordinator (
742745 client_http,
743746 router,
744747 auth_token,
@@ -787,19 +790,13 @@ impl<T: WasmInstance> WasmModuleInstance<T> {
787790 let auth_token = replica_ctx. call_reducer_auth_token . clone ( ) ;
788791 let prepare_id_owned = prepare_id. to_owned ( ) ;
789792 loop {
790- let decision = std:: thread:: scope ( |s| {
791- s. spawn ( || {
792- handle. block_on ( Self :: query_coordinator_status (
793- & client,
794- & router,
795- auth_token. clone ( ) ,
796- coordinator_identity,
797- & prepare_id_owned,
798- ) )
799- } )
800- . join ( )
801- . expect ( "coordinator poll thread panicked" )
802- } ) ;
793+ let decision = block_on_scoped ( & handle, Self :: query_coordinator_status (
794+ & client,
795+ & router,
796+ auth_token. clone ( ) ,
797+ coordinator_identity,
798+ & prepare_id_owned,
799+ ) ) ;
803800 match decision {
804801 Some ( commit) => return commit,
805802 None => std:: thread:: sleep ( Duration :: from_secs ( 5 ) ) ,
@@ -1157,9 +1154,7 @@ impl InstanceCommon {
11571154
11581155 let replica_ctx = inst. replica_ctx ( ) . clone ( ) ;
11591156 let handle = tokio:: runtime:: Handle :: current ( ) ;
1160- std:: thread:: scope ( |s| {
1161- s. spawn ( || {
1162- handle. block_on ( async {
1157+ block_on_scoped ( & handle, async {
11631158 // Wait for A's coordinator log (committed atomically with the tx) to be
11641159 // durable before sending COMMIT to B. This guarantees that if A crashes
11651160 // after sending COMMIT, recovery can retransmit from the durable log.
@@ -1218,10 +1213,6 @@ impl InstanceCommon {
12181213 }
12191214 }
12201215 }
1221- } ) ;
1222- } )
1223- . join ( )
1224- . expect ( "2PC coordination thread panicked" ) ;
12251216 } ) ;
12261217 }
12271218
0 commit comments