Skip to content

Commit

Permalink
fix(rust): protect the start of a grpc forwarder against an incorrect…
Browse files Browse the repository at this point in the history
… configuration
  • Loading branch information
etorreborre committed Feb 25, 2025
1 parent 1cff592 commit fe9d301
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -325,14 +325,30 @@ impl Authority {
.add_consumer(&address.into(), secure_channel_flow_control_id);

let url = telemetry_endpoint_url.to_string();
let uri = url
if let Ok(uri) = url
.parse::<Uri>()
.map_err(|e| Error::new(Origin::Ockam, Kind::Invalid, e))?;
debug!("start a grpc forwarder at '{uri}'");
ctx.start_worker(
address,
GrpcForwarder::new(uri).await.map_err(ApiError::core)?,
)?
.map_err(|e| Error::new(Origin::Ockam, Kind::Invalid, e))
{
debug!("Start a grpc forwarder at '{uri}'");
match GrpcForwarder::new(uri.clone())
.await
.map_err(ApiError::core)
{
Ok(grpc_forwarder) => match ctx.start_worker(address, grpc_forwarder) {
Ok(_) => {
debug!("Started a grpc forwarder at '{uri}'");
}
Err(e) => {
error!("Cannot start the grpc forwarder at '{uri}': {e:?}")
}
},
Err(e) => {
error!("Cannot start the grpc forwarder: {e:?}")
}
}
} else {
error!("Cannot start the grpc forwarder, can't parse the opentelemetry endpoint: {url}")
}
};
Ok(())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use ockam_core::errcode::{Kind, Origin};
use ockam_core::{async_trait, Routed, Worker};
use ockam_node::Context;
use std::future;
use std::time::Duration;
use tonic::body::BoxBody;
use tonic::client::GrpcService;
use tonic::transport::Channel;
Expand All @@ -28,6 +29,7 @@ impl GrpcForwarder {
"cannot create a TLS config for the HttpForwarder channel at {uri:?}: {e:?}"
))
})?
.connect_timeout(Duration::from_secs(5))
.connect()
.await
.map_err(|e| ApiError::message(format!("cannot connect to {uri:?}: {e:?}")))?;
Expand Down

0 comments on commit fe9d301

Please sign in to comment.