@@ -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 }
@@ -262,6 +261,7 @@ impl ActiveChannel {
262261 tx. clone ( ) ,
263262 picker. clone ( ) ,
264263 connectivity_state. clone ( ) ,
264+ runtime. clone ( ) ,
265265 ) ;
266266
267267 let resolver_helper = Box :: new ( tx. clone ( ) ) ;
@@ -279,7 +279,7 @@ impl ActiveChannel {
279279 let resolver_opts = name_resolution:: ResolverOptions {
280280 authority,
281281 work_scheduler,
282- runtime : Arc :: new ( TokioRuntime { } ) ,
282+ runtime : runtime . clone ( ) ,
283283 } ;
284284 let resolver = rb. build ( & target, resolver_opts) ;
285285
@@ -360,6 +360,7 @@ pub(crate) struct InternalChannelController {
360360 wqtx : WorkQueueTx ,
361361 picker : Arc < Watcher < Arc < dyn Picker > > > ,
362362 connectivity_state : Arc < Watcher < ConnectivityState > > ,
363+ runtime : Arc < dyn Runtime > ,
363364}
364365
365366impl InternalChannelController {
@@ -369,8 +370,9 @@ impl InternalChannelController {
369370 wqtx : WorkQueueTx ,
370371 picker : Arc < Watcher < Arc < dyn Picker > > > ,
371372 connectivity_state : Arc < Watcher < ConnectivityState > > ,
373+ runtime : Arc < dyn Runtime > ,
372374 ) -> Self {
373- let lb = Arc :: new ( GracefulSwitchBalancer :: new ( wqtx. clone ( ) ) ) ;
375+ let lb = Arc :: new ( GracefulSwitchBalancer :: new ( wqtx. clone ( ) , runtime . clone ( ) ) ) ;
374376
375377 Self {
376378 lb,
@@ -380,6 +382,7 @@ impl InternalChannelController {
380382 wqtx,
381383 picker,
382384 connectivity_state,
385+ runtime,
383386 }
384387 }
385388
@@ -429,6 +432,7 @@ impl load_balancing::ChannelController for InternalChannelController {
429432 Box :: new ( move |k : SubchannelKey | {
430433 scp. unregister_subchannel ( & k) ;
431434 } ) ,
435+ self . runtime . clone ( ) ,
432436 ) ;
433437 let _ = self . subchannel_pool . register_subchannel ( & key, isc. clone ( ) ) ;
434438 self . new_esc_for_isc ( isc)
@@ -454,6 +458,7 @@ pub(super) struct GracefulSwitchBalancer {
454458 policy_builder : Mutex < Option < Arc < dyn LbPolicyBuilder > > > ,
455459 work_scheduler : WorkQueueTx ,
456460 pending : Mutex < bool > ,
461+ runtime : Arc < dyn Runtime > ,
457462}
458463
459464impl WorkScheduler for GracefulSwitchBalancer {
@@ -478,12 +483,13 @@ impl WorkScheduler for GracefulSwitchBalancer {
478483}
479484
480485impl GracefulSwitchBalancer {
481- fn new ( work_scheduler : WorkQueueTx ) -> Self {
486+ fn new ( work_scheduler : WorkQueueTx , runtime : Arc < dyn Runtime > ) -> Self {
482487 Self {
483488 policy_builder : Mutex :: default ( ) ,
484489 policy : Mutex :: default ( ) , // new(None::<Box<dyn LbPolicy>>),
485490 work_scheduler,
486491 pending : Mutex :: default ( ) ,
492+ runtime,
487493 }
488494 }
489495
@@ -501,6 +507,7 @@ impl GracefulSwitchBalancer {
501507 let builder = GLOBAL_LB_REGISTRY . get_policy ( policy_name) . unwrap ( ) ;
502508 let newpol = builder. build ( LbPolicyOptions {
503509 work_scheduler : self . clone ( ) ,
510+ runtime : self . runtime . clone ( ) ,
504511 } ) ;
505512 * self . policy_builder . lock ( ) . unwrap ( ) = Some ( builder) ;
506513 * p = Some ( newpol) ;
0 commit comments