diff --git a/volo-thrift/src/client/layer/timeout.rs b/volo-thrift/src/client/layer/timeout.rs index 12763359..30739cdd 100644 --- a/volo-thrift/src/client/layer/timeout.rs +++ b/volo-thrift/src/client/layer/timeout.rs @@ -54,7 +54,7 @@ where None => self.inner.call(cx, req).await.map_err(Into::into), } } else { - self.inner.call(cx, req).await.map_err(Into::into) + unreachable!("rpc_info.config should never be None") } } } diff --git a/volo-thrift/src/client/mod.rs b/volo-thrift/src/client/mod.rs index 833045ae..02e1f4ed 100644 --- a/volo-thrift/src/client/mod.rs +++ b/volo-thrift/src/client/mod.rs @@ -62,6 +62,8 @@ pub struct ClientBuilder { mk_lb: LB, _marker: PhantomData<(*const Req, *const Resp)>, + disable_timeout_layer: bool, + #[cfg(feature = "multiplex")] multiplex: bool, } @@ -93,6 +95,8 @@ impl mk_lb: LbConfig::new(WeightedRandomBalance::new(), DummyDiscover {}), _marker: PhantomData, + disable_timeout_layer: false, + #[cfg(feature = "multiplex")] multiplex: false, } @@ -120,6 +124,8 @@ impl make_codec: self.make_codec, mk_lb: self.mk_lb.load_balance(load_balance), + disable_timeout_layer: self.disable_timeout_layer, + #[cfg(feature = "multiplex")] multiplex: self.multiplex, } @@ -143,6 +149,8 @@ impl make_codec: self.make_codec, mk_lb: self.mk_lb.discover(discover), + disable_timeout_layer: self.disable_timeout_layer, + #[cfg(feature = "multiplex")] multiplex: self.multiplex, } @@ -198,6 +206,13 @@ impl ClientBuilder Self { + self.disable_timeout_layer = true; + self + } + pub fn mk_load_balance( self, mk_load_balance: NLB, @@ -216,6 +231,8 @@ impl ClientBuilder ClientBuilder ClientBuilder ClientBuilder bar -> baz. /// - /// The overall order for layers is: Timeout -> outer -> LoadBalance -> [inner] -> transport. + /// The overall order for layers is: outer -> LoadBalance -> [inner] -> transport. pub fn layer_inner( self, layer: Inner, @@ -318,6 +339,8 @@ impl ClientBuilder ClientBuilder ClientBuilder foo -> bar. /// - /// The overall order for layers is: Timeout -> [outer] -> LoadBalance -> inner -> transport. + /// The overall order for layers is: [outer] -> Timeout -> LoadBalance -> inner -> transport. pub fn layer_outer_front( self, layer: Outer, @@ -390,6 +415,8 @@ impl ClientBuilder ClientBuilder ClientBuilder where C: volo::client::MkClient< - Client, crate::Error>>, + Client< + BoxCloneService< + ClientContext, + Req, + Option, + >::Error, + >, + >, >, LB: MkLbLayer, LB::Layer: Layer, - >::Service: - Service> + 'static + Send + Clone + Sync, - <>::Service as Service>::Error: Into, + >::Service: Service, Error = Error> + + 'static + + Send + + Clone + + Sync, for<'cx> <>::Service as Service>::Future<'cx>: Send, Req: EntryMessage + Send + 'static + Sync + Clone, @@ -485,14 +523,7 @@ where for<'cx> >::Future<'cx>: Send, MkT: MakeTransport, MkC: MakeCodec + Sync, - OL: Layer< - BoxCloneService< - ClientContext, - Req, - Option, - <>::Service as Service>::Error, - >, - >, + OL: Layer, Error>>, OL::Service: Service> + 'static + Send + Clone + Sync, for<'cx> >::Future<'cx>: Send, @@ -528,11 +559,15 @@ where }, }; - let transport = TimeoutLayer::new().layer(self.outer_layer.layer(BoxCloneService::new( - self.mk_lb.make().layer(self.inner_layer.layer(msg_svc)), - ))); - - let transport = BoxCloneService::new(transport); + let transport = if !self.disable_timeout_layer { + BoxCloneService::new(self.outer_layer.layer(BoxCloneService::new( + TimeoutLayer::new().layer(self.mk_lb.make().layer(self.inner_layer.layer(msg_svc))), + ))) + } else { + BoxCloneService::new(self.outer_layer.layer(BoxCloneService::new( + self.mk_lb.make().layer(self.inner_layer.layer(msg_svc)), + ))) + }; self.mk_client.mk_client(Client { inner: Arc::new(ClientInner {