Open source, composable payments platform | PCI compliant | SaaS and Self-host options | Enables connectivity to multiple payment, payout, fraud, vault and tokenization providers | Uplifts authorization with intelligent routing and revenue recovery | Reduce payment processing costs with cost observability | Reduces payment ops with reconciliation
Rust adyenbeginner-friendlyfeaturedfinancefintechhacktoberfesthigh-performanceopen-sourceorchestrationpaymentpayment-gatewaypayment-integrationpayment-processingpaymentspayments-platformrestful-apirustsdkstripeworks-with-react
fix(grpc_client): apply per-RPC timeout to unified connector service calls (#12850)
gopikrishna0001e8119941d6b
diff --git a/config/config.example.toml b/config/config.example.tomlindex 52b4935092..33f63e458b 100644--- a/config/config.example.toml+++ b/config/config.example.toml@@ -1342,6 +1342,7 @@ url = "http://localhost:8080" # Open Router URL[grpc_client.unified_connector_service]base_url = "http://localhost:8000" # Unified Connector Service Base URLconnection_timeout = 10 # Connection Timeout Duration in Seconds+request_timeout = 35 # Per-RPC Request Timeout in Secondsucs_only_connectors = "imerchantsolutions, paytm, phonepe, hyperpg, revolv3, fiservcommercehub, absa_sanlam, interpayments, dlocal, barclaycard" # Comma-separated list of connectors that use UCS onlyucs_psync_disabled_connectors = "cashtocode, trustly" # Comma-separated list of connectors to disable UCS PSync calldiff --git a/config/deployments/env_specific.toml b/config/deployments/env_specific.tomlindex f22ef5642c..1645a9b86a 100644--- a/config/deployments/env_specific.toml+++ b/config/deployments/env_specific.toml@@ -412,6 +412,7 @@ payment_method = "payment_method_types" # <payment_method> = comma-separated clo[grpc_client.unified_connector_service]base_url = "http://localhost:8000" # Unified Connector Service Base URLconnection_timeout = 10 # Connection Timeout Duration in Seconds+request_timeout = 35 # Per-RPC Request Timeout in Secondsucs_only_connectors = "imerchantsolutions, paytm, phonepe, hyperpg, revolv3, fiservcommercehub, absa_sanlam, interpayments, payconex, dlocal, barclaycard" # Comma-separated list of connectors that use UCS onlyucs_psync_disabled_connectors = "cashtocode, trustly" # Comma-separated list of connectors to disable UCS PSync calldiff --git a/config/development.toml b/config/development.tomlindex 5c73a298bb..fdaf871112 100644--- a/config/development.toml+++ b/config/development.toml@@ -1487,6 +1487,7 @@ enabled = "true"[grpc_client.unified_connector_service]base_url = "http://localhost:8000"connection_timeout = 10+request_timeout = 35ucs_only_connectors = "imerchantsolutions, paytm, phonepe, hyperpg, revolv3, fiservcommercehub, absa_sanlam, interpayments, payconex, dlocal, barclaycard" # Comma-separated list of connectors that use UCS onlyucs_psync_disabled_connectors = "cashtocode, trustly" # Comma-separated list of connectors to disable UCS PSync calldiff --git a/crates/external_services/src/grpc_client/unified_connector_service.rs b/crates/external_services/src/grpc_client/unified_connector_service.rsindex e5e3e1b21e..0a2715a407 100644--- a/crates/external_services/src/grpc_client/unified_connector_service.rs+++ b/crates/external_services/src/grpc_client/unified_connector_service.rs@@ -57,7 +57,11 @@ pub struct UnifiedConnectorServiceClientConfig {pub base_url: Url,/// Contains the connection timeout duration in seconds- pub connection_timeout: u64,+ pub connection_timeout: UcsConnectionTimeoutInSeconds,++ /// Per-RPC timeout (seconds) for calls to the unified connector service.+ #[serde(default)]+ pub request_timeout: UcsRequestTimeoutInSeconds,/// Set of external services/connectors available for the unified connector service#[serde(default, deserialize_with = "deserialize_hashset")]@@ -68,6 +72,34 @@ pub struct UnifiedConnectorServiceClientConfig {pub ucs_psync_disabled_connectors: HashSet<Connector>,}+/// Connection timeout for the Unified Connector Service in seconds.+#[derive(Debug, Clone, Copy, serde::Deserialize, serde::Serialize)]+pub struct UcsConnectionTimeoutInSeconds(u64);++impl UcsConnectionTimeoutInSeconds {+ /// Return the timeout as a [`Duration`].+ pub fn as_duration(self) -> Duration {+ Duration::from_secs(self.0)+ }+}++/// Per-RPC request timeout for the Unified Connector Service in seconds.+#[derive(Debug, Clone, Copy, serde::Deserialize, serde::Serialize)]+pub struct UcsRequestTimeoutInSeconds(u64);++impl Default for UcsRequestTimeoutInSeconds {+ fn default() -> Self {+ Self(consts::DEFAULT_UCS_REQUEST_TIMEOUT_SECS)+ }+}++impl UcsRequestTimeoutInSeconds {+ /// Return the timeout as a [`Duration`].+ pub fn as_duration(self) -> Duration {+ Duration::from_secs(self.0)+ }+}+/// Contains the Connector Auth Type and related authentication data.#[derive(Debug, Clone, serde::Deserialize, serde::Serialize)]pub struct ConnectorAuthMetadata {@@ -149,17 +181,14 @@ pub struct HyperswitchVaultMetadata {pub vault_auth_data: VaultConnectorAuth,}-/// Builds a gRPC client with timeout handling+/// Builds a gRPC client. `$connection_timeout` bounds connect; `$request_timeout` bounds each RPC.#[macro_export]macro_rules! build_grpc_client {- ($client:ty, $name:expr, $uri:expr, $timeout:expr) => {{- match timeout(- Duration::from_secs($timeout),- <$client>::connect($uri.clone()),- )- .await- {- Ok(Ok(client)) => client,+ ($client:ty, $name:expr, $uri:expr, $connection_timeout:expr, $request_timeout:expr) => {{+ let endpoint = tonic::transport::Channel::builder($uri.clone())+ .timeout($request_timeout.as_duration());+ match timeout($connection_timeout.as_duration(), endpoint.connect()).await {+ Ok(Ok(channel)) => <$client>::new(channel),Ok(Err(err)) => {router_env::logger::error!("Failed to connect to Unified Connector Service for {}: {:?}",@@ -206,7 +235,8 @@ impl UnifiedConnectorServiceClient {}};- let timeout = unified_connector_service_client_config.connection_timeout;+ let connection_timeout = unified_connector_service_client_config.connection_timeout;+ let request_timeout = unified_connector_service_client_config.request_timeout;let payment_service_client = build_grpc_client!(payments_grpc::payment_service_client::PaymentServiceClient<@@ -214,7 +244,8 @@ impl UnifiedConnectorServiceClient {>,"payment_service_client",uri,- timeout+ connection_timeout,+ request_timeout);let refund_service_client = build_grpc_client!(@@ -223,7 +254,8 @@ impl UnifiedConnectorServiceClient {>,"refund_service_client",uri,- timeout+ connection_timeout,+ request_timeout);let event_service_client = build_grpc_client!(@@ -232,7 +264,8 @@ impl UnifiedConnectorServiceClient {>,"event_service_client",uri,- timeout+ connection_timeout,+ request_timeout);let recurring_payment_service_client = build_grpc_client!(@@ -241,7 +274,8 @@ impl UnifiedConnectorServiceClient {>,"recurring_payment_service_client",uri,- timeout+ connection_timeout,+ request_timeout);let dispute_service_client = build_grpc_client!(@@ -250,7 +284,8 @@ impl UnifiedConnectorServiceClient {>,"dispute_service_client",uri,- timeout+ connection_timeout,+ request_timeout);let payment_method_service_client = build_grpc_client!(@@ -259,7 +294,8 @@ impl UnifiedConnectorServiceClient {>,"payment_method_service_client",uri,- timeout+ connection_timeout,+ request_timeout);let customer_service_client = build_grpc_client!(@@ -268,21 +304,24 @@ impl UnifiedConnectorServiceClient {>,"customer_service_client",uri,- timeout+ connection_timeout,+ request_timeout);let merchant_authentication_service_client = build_grpc_client!(payments_grpc::merchant_authentication_service_client::MerchantAuthenticationServiceClient<tonic::transport::Channel>,"merchant_authentication_service_client",uri,- timeout+ connection_timeout,+ request_timeout);let payment_method_authentication_service_client = build_grpc_client!(payments_grpc::payment_method_authentication_service_client::PaymentMethodAuthenticationServiceClient<tonic::transport::Channel>,"payment_method_authentication_service_client",uri,- timeout+ connection_timeout,+ request_timeout);let payout_service_client = build_grpc_client!(@@ -291,7 +330,8 @@ impl UnifiedConnectorServiceClient {>,"payout_service_client",uri,- timeout+ connection_timeout,+ request_timeout);let surcharge_service_client = build_grpc_client!(@@ -300,7 +340,8 @@ impl UnifiedConnectorServiceClient {>,"surcharge_service_client",uri,- timeout+ connection_timeout,+ request_timeout);logger::info!("Successfully connected to Unified Connector Service");diff --git a/crates/external_services/src/lib.rs b/crates/external_services/src/lib.rsindex 7d6f655601..83c39fb863 100644--- a/crates/external_services/src/lib.rs+++ b/crates/external_services/src/lib.rs@@ -62,6 +62,9 @@ pub mod date_time {/// Crate specific constantspub mod consts {+ /// Default per-RPC timeout (seconds) for unified connector service calls.+ pub(crate) const DEFAULT_UCS_REQUEST_TIMEOUT_SECS: u64 = 35;+/// General purpose base64 engine#[cfg(feature = "aws_kms")]pub(crate) const BASE64_ENGINE: base64::engine::GeneralPurpose =