Skip to content

Commit d5dbc6a

Browse files
authored
fix(rpc): workaround for tonic hanging on large error message (#18639)
Signed-off-by: Bugen Zhao <[email protected]>
1 parent a5ec3ea commit d5dbc6a

File tree

3 files changed

+46
-30
lines changed

3 files changed

+46
-30
lines changed

Cargo.lock

+15-14
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/common/metrics/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ normal = ["workspace-hack"]
1717
[dependencies]
1818
auto_impl = "1"
1919
bytes = "1"
20+
cfg-or-panic = "0.2"
2021
clap = { workspace = true }
2122
easy-ext = "1"
2223
futures = { version = "0.3", default-features = false, features = ["alloc"] }

src/common/metrics/src/monitor/connection.rs

+30-16
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use std::sync::LazyLock;
2222
use std::task::{Context, Poll};
2323
use std::time::Duration;
2424

25+
use cfg_or_panic::cfg_or_panic;
2526
use futures::FutureExt;
2627
use http::Uri;
2728
use hyper_util::client::legacy::connect::dns::{GaiAddrs, GaiFuture, GaiResolver, Name};
@@ -591,23 +592,40 @@ impl Service<Name> for MonitoredGaiResolver {
591592
}
592593
}
593594

595+
#[cfg_or_panic(not(madsim))]
596+
fn monitored_http_connector(
597+
connection_type: impl Into<String>,
598+
config: TcpConfig,
599+
) -> MonitoredConnection<HttpConnector<MonitoredGaiResolver>, MonitorNewConnectionImpl> {
600+
let resolver = MonitoredGaiResolver::default();
601+
let mut http = HttpConnector::new_with_resolver(resolver);
602+
603+
http.enforce_http(false);
604+
http.set_nodelay(config.tcp_nodelay);
605+
http.set_keepalive(config.keepalive_duration);
606+
607+
monitor_connector(http, connection_type)
608+
}
609+
610+
/// Attach general configurations to the endpoint.
611+
#[cfg_or_panic(not(madsim))]
612+
fn configure_endpoint(endpoint: Endpoint) -> Endpoint {
613+
// This is to mitigate https://github.com/risingwavelabs/risingwave/issues/18039.
614+
// TODO: remove this after https://github.com/hyperium/hyper/issues/3724 gets resolved.
615+
endpoint.http2_max_header_list_size(16 * 1024 * 1024)
616+
}
617+
594618
#[easy_ext::ext(EndpointExt)]
595619
impl Endpoint {
596620
pub async fn monitored_connect(
597-
self,
621+
mut self,
598622
connection_type: impl Into<String>,
599623
config: TcpConfig,
600624
) -> Result<Channel, tonic::transport::Error> {
601625
#[cfg(not(madsim))]
602626
{
603-
let resolver = MonitoredGaiResolver::default();
604-
let mut http = HttpConnector::new_with_resolver(resolver);
605-
606-
http.enforce_http(false);
607-
http.set_nodelay(config.tcp_nodelay);
608-
http.set_keepalive(config.keepalive_duration);
609-
610-
let connector = monitor_connector(http, connection_type);
627+
self = configure_endpoint(self);
628+
let connector = monitored_http_connector(connection_type, config);
611629
self.connect_with_connector(connector).await
612630
}
613631
#[cfg(madsim)]
@@ -618,16 +636,12 @@ impl Endpoint {
618636

619637
#[cfg(not(madsim))]
620638
pub fn monitored_connect_lazy(
621-
self,
639+
mut self,
622640
connection_type: impl Into<String>,
623641
config: TcpConfig,
624642
) -> Channel {
625-
let mut http = HttpConnector::new();
626-
http.enforce_http(false);
627-
http.set_nodelay(config.tcp_nodelay);
628-
http.set_keepalive(config.keepalive_duration);
629-
630-
let connector = monitor_connector(http, connection_type);
643+
self = configure_endpoint(self);
644+
let connector = monitored_http_connector(connection_type, config);
631645
self.connect_with_connector_lazy(connector)
632646
}
633647
}

0 commit comments

Comments
 (0)