@@ -37,17 +37,16 @@ use std::{
3737} ;
3838
3939use tokio:: sync:: { mpsc, oneshot, watch, Notify } ;
40- use tokio:: task:: AbortHandle ;
4140
4241use serde_json:: json;
4342use tonic:: async_trait;
4443use url:: Url ; // NOTE: http::Uri requires non-empty authority portion of URI
4544
46- use crate :: credentials :: Credentials ;
45+ use crate :: attributes :: Attributes ;
4746use crate :: rt;
4847use crate :: service:: { Request , Response , Service } ;
49- use crate :: { attributes:: Attributes , rt:: tokio:: TokioRuntime } ;
5048use crate :: { client:: ConnectivityState , rt:: Runtime } ;
49+ use crate :: { credentials:: Credentials , rt:: default_runtime} ;
5150
5251use super :: service_config:: ServiceConfig ;
5352use super :: transport:: { TransportRegistry , GLOBAL_TRANSPORT_REGISTRY } ;
@@ -156,7 +155,7 @@ impl Channel {
156155 inner : Arc :: new ( PersistentChannel :: new (
157156 target,
158157 credentials,
159- Arc :: new ( rt :: tokio :: TokioRuntime { } ) ,
158+ default_runtime ( ) ,
160159 options,
161160 ) ) ,
162161 }
@@ -280,7 +279,7 @@ impl ActiveChannel {
280279 let resolver_opts = name_resolution:: ResolverOptions {
281280 authority,
282281 work_scheduler,
283- runtime : Arc :: new ( TokioRuntime { } ) ,
282+ runtime : runtime . clone ( ) ,
284283 } ;
285284 let resolver = rb. build ( & target, resolver_opts) ;
286285
@@ -373,7 +372,7 @@ impl InternalChannelController {
373372 connectivity_state : Arc < Watcher < ConnectivityState > > ,
374373 runtime : Arc < dyn Runtime > ,
375374 ) -> Self {
376- let lb = Arc :: new ( GracefulSwitchBalancer :: new ( wqtx. clone ( ) ) ) ;
375+ let lb = Arc :: new ( GracefulSwitchBalancer :: new ( wqtx. clone ( ) , runtime . clone ( ) ) ) ;
377376
378377 Self {
379378 lb,
@@ -459,6 +458,7 @@ pub(super) struct GracefulSwitchBalancer {
459458 policy_builder : Mutex < Option < Arc < dyn LbPolicyBuilder > > > ,
460459 work_scheduler : WorkQueueTx ,
461460 pending : Mutex < bool > ,
461+ runtime : Arc < dyn Runtime > ,
462462}
463463
464464impl WorkScheduler for GracefulSwitchBalancer {
@@ -483,12 +483,13 @@ impl WorkScheduler for GracefulSwitchBalancer {
483483}
484484
485485impl GracefulSwitchBalancer {
486- fn new ( work_scheduler : WorkQueueTx ) -> Self {
486+ fn new ( work_scheduler : WorkQueueTx , runtime : Arc < dyn Runtime > ) -> Self {
487487 Self {
488488 policy_builder : Mutex :: default ( ) ,
489489 policy : Mutex :: default ( ) , // new(None::<Box<dyn LbPolicy>>),
490490 work_scheduler,
491491 pending : Mutex :: default ( ) ,
492+ runtime,
492493 }
493494 }
494495
@@ -506,6 +507,7 @@ impl GracefulSwitchBalancer {
506507 let builder = GLOBAL_LB_REGISTRY . get_policy ( policy_name) . unwrap ( ) ;
507508 let newpol = builder. build ( LbPolicyOptions {
508509 work_scheduler : self . clone ( ) ,
510+ runtime : self . runtime . clone ( ) ,
509511 } ) ;
510512 * self . policy_builder . lock ( ) . unwrap ( ) = Some ( builder) ;
511513 * p = Some ( newpol) ;
0 commit comments