fix(rocketmq): wire Advanced timeout through and tighten Docker remap
This commit is contained in:
5 files changed
+408
-72
No files matched your search
@@ -104,14 +104,15 @@ impl RocketMqAdmin {
|
||||
pub async fn new(cfg: MqAdminConfig, launch: AgentLaunchSpec) -> Result<Self, String> {
|
||||
let mut client = AgentDriverClient::spawn(launch).await?;
|
||||
|
||||
// Handshake
|
||||
// Handshake / connect use Advanced connect timeout; ops RPC keep query timeout.
|
||||
let _: serde_json::Value =
|
||||
client.call_with_timeout("handshake", serde_json::json!({}), cfg.rpc_timeout()).await?;
|
||||
client.call_with_timeout("handshake", serde_json::json!({}), Some(cfg.connect_timeout())).await?;
|
||||
|
||||
// Build the connection params from MqAdminConfig
|
||||
let conn_params = build_connection_params(&cfg);
|
||||
let connect_params = serde_json::json!({ "connection": conn_params });
|
||||
let _: serde_json::Value = client.call_with_timeout("connect", connect_params, cfg.rpc_timeout()).await?;
|
||||
let _: serde_json::Value =
|
||||
client.call_with_timeout("connect", connect_params, Some(cfg.connect_timeout())).await?;
|
||||
|
||||
log::info!("RocketMQ admin connected via agent (namesrv: {})", namesrv_addr(&cfg));
|
||||
|
||||
@@ -840,6 +841,7 @@ fn build_connection_params(cfg: &MqAdminConfig) -> serde_json::Value {
|
||||
"secret_key": secret_key,
|
||||
"tls_skip_verify": cfg.tls_skip_verify,
|
||||
"request_timeout_ms": cfg.request_timeout_ms(),
|
||||
"connect_timeout_ms": cfg.connect_timeout_ms(),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -964,12 +966,10 @@ async fn probe_namesrv_tcp(namesrv: &str, budget: Duration) -> Result<(), String
|
||||
}
|
||||
|
||||
let deadline = tokio::time::Instant::now() + budget;
|
||||
// Multi-NS HA: cap each attempt so a blackholed first node leaves budget for later hosts.
|
||||
let per_attempt = if hosts.len() <= 1 {
|
||||
budget
|
||||
} else {
|
||||
(budget / hosts.len() as u32).clamp(Duration::from_millis(500), Duration::from_secs(3))
|
||||
};
|
||||
// Multi-NS HA: share budget across hosts so a blackholed first node leaves time for later ones.
|
||||
// Floor 500ms; no hard 3s cap so Advanced connect timeout can raise the per-host attempt.
|
||||
let per_attempt =
|
||||
if hosts.len() <= 1 { budget } else { (budget / hosts.len() as u32).max(Duration::from_millis(500)) };
|
||||
let mut last_error = String::new();
|
||||
for host in &hosts {
|
||||
let remaining = deadline.saturating_duration_since(tokio::time::Instant::now());
|
||||
@@ -1101,6 +1101,21 @@ mod tests {
|
||||
assert_eq!(params.get("access_key").and_then(|v| v.as_str()), Some("rocket"));
|
||||
assert_eq!(params.get("secret_key").and_then(|v| v.as_str()), Some("secret"));
|
||||
assert_eq!(params.get("request_timeout_ms").and_then(|v| v.as_u64()), Some(30_000));
|
||||
assert_eq!(
|
||||
params.get("connect_timeout_ms").and_then(|v| v.as_u64()),
|
||||
Some(crate::mq::config::DEFAULT_MQ_CONNECT_TIMEOUT_SECS.saturating_mul(1000).max(1_000))
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn connection_params_follow_advanced_timeouts() {
|
||||
let mut cfg = rocketmq_config(serde_json::json!({ "namesrvAddr": "127.0.0.1:9876" }), MqAuth::None);
|
||||
cfg.query_timeout_secs = 120;
|
||||
cfg.connect_timeout_secs = 15;
|
||||
|
||||
let params = build_connection_params(&cfg);
|
||||
assert_eq!(params.get("request_timeout_ms").and_then(|v| v.as_u64()), Some(120_000));
|
||||
assert_eq!(params.get("connect_timeout_ms").and_then(|v| v.as_u64()), Some(15_000));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -118,6 +118,11 @@ impl MqAdminConfig {
|
||||
Duration::from_secs(self.connect_timeout_secs.max(1))
|
||||
}
|
||||
|
||||
/// Milliseconds for agent `connect_timeout_ms` (Advanced connect timeout).
|
||||
pub fn connect_timeout_ms(&self) -> u64 {
|
||||
self.connect_timeout_secs.saturating_mul(1000).max(1_000)
|
||||
}
|
||||
|
||||
pub fn token_signing_configured(&self) -> bool {
|
||||
self.token_signing.as_ref().is_some_and(MqTokenSigningConfig::is_configured)
|
||||
}
|
||||
@@ -285,6 +290,7 @@ mod tests {
|
||||
assert_eq!(mqc.query_timeout_secs, 120);
|
||||
assert_eq!(mqc.connect_timeout_secs, 15);
|
||||
assert_eq!(mqc.request_timeout_ms(), 120_000);
|
||||
assert_eq!(mqc.connect_timeout_ms(), 15_000);
|
||||
assert_eq!(mqc.rpc_timeout(), Some(std::time::Duration::from_secs(120)));
|
||||
}
|
||||
|
||||
|
||||
@@ -168,9 +168,8 @@ async fn build_adapter_with_connect_timeout(
|
||||
// RocketMQ: TCP-probe NameServer outside the connect wall so cold JVM spawn
|
||||
// retains the full connect_timeout (probe used to steal up to half of it).
|
||||
if mqc.system_kind == MqSystemKindInternal::RocketMq {
|
||||
// Probe runs outside the connect wall; scale with connect_timeout so HA NameServer
|
||||
// lists are not starved by a hard 2s cap, but keep an upper bound for snappy UX.
|
||||
let probe_budget = (budget / 2).clamp(std::time::Duration::from_millis(500), std::time::Duration::from_secs(5));
|
||||
// Probe runs outside the connect wall; scale with Advanced connect_timeout (no hard 5s cap).
|
||||
let probe_budget = (budget / 2).max(std::time::Duration::from_millis(500));
|
||||
crate::mq::adapters::rocketmq::probe_namesrv_before_connect(&mqc, probe_budget).await?;
|
||||
}
|
||||
match tokio::time::timeout(budget, build_adapter(mqc, agent_launch)).await {
|
||||
|
||||
Reference in new issue
Block a user