Skip to content

fix: normalize make_transport error to TransportError #271

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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