Skip to content

Commit

Permalink
fix: normalize make_transport error to TransportError
Browse files Browse the repository at this point in the history
  • Loading branch information
Millione committed Dec 4, 2023
1 parent e8109a5 commit effc0f4
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 14 deletions.
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion volo-thrift/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "volo-thrift"
version = "0.8.2"
version = "0.8.3"
edition.workspace = true
homepage.workspace = true
repository.workspace = true
Expand Down
8 changes: 4 additions & 4 deletions volo-thrift/src/transport/pool/make_transport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
use std::{fmt::Debug, hash::Hash};

use motore::{service::UnaryService, BoxError};
use motore::service::UnaryService;

use super::{Pool, Poolable, Pooled};

Expand Down Expand Up @@ -48,14 +48,14 @@ where
Key: Clone + Eq + Hash + Debug + Send + 'static,
MT: UnaryService<Key> + Send + Clone + 'static + Sync,
MT::Response: Poolable + Send,
MT::Error: Into<BoxError>,
MT::Error: Into<pilota::thrift::TransportError>,
{
type Response = Pooled<Key, MT::Response>;

type Error = BoxError;
type Error = crate::Error;

async fn call(&self, key: Key) -> Result<Self::Response, Self::Error> {
let mt = self.inner.clone();
self.pool.get(key, mt).await
self.pool.get(key, mt).await.map_err(Into::into)
}
}
18 changes: 12 additions & 6 deletions volo-thrift/src/transport/pool/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use futures::{
};
use linked_hash_map::LinkedHashMap;
pub use make_transport::PooledMakeTransport;
use motore::{service::UnaryService, BoxError};
use motore::service::UnaryService;
use pin_project::pin_project;
use started::Started as _;
use tokio::{
Expand Down Expand Up @@ -201,10 +201,14 @@ where
Pool { inner }
}

pub async fn get<MT>(&self, key: Key, mt: MT) -> Result<Pooled<Key, T>, BoxError>
pub async fn get<MT>(
&self,
key: Key,
mt: MT,
) -> Result<Pooled<Key, T>, pilota::thrift::TransportError>
where
MT: UnaryService<Key, Response = T> + Send + 'static + Sync,
MT::Error: Into<BoxError>,
MT::Error: Into<pilota::thrift::TransportError>,
{
let (rx, _waiter_token) = {
let mut inner = self.inner.lock().volo_unwrap();
Expand Down Expand Up @@ -270,9 +274,11 @@ where
}
// means connection pool is dropped
Either::Left((Err(e), _)) => {
let e = e.into();
tracing::error!("[VOLO] wait a idle connection error: {:?}", e);
Err(e)
Err(pilota::thrift::TransportError::new(
pilota::thrift::TransportErrorKind::Unknown,
format!("wait a idle connection error: {:?}", e),
))
}
// maybe there is no more connection put back into pool and waiter will block forever,
// so just return error
Expand Down Expand Up @@ -537,7 +543,7 @@ where
if let Some(t) = value {
// means doesn't send success
// then put back to idle list
let idle = self.idle.entry(key).or_insert_with(Vec::new);
let idle = self.idle.entry(key).or_default();
if idle.len() < self.max_idle_per_key {
idle.push(Idle {
inner: t,
Expand Down

0 comments on commit effc0f4

Please sign in to comment.