SkyeBeFreeman opened a new issue, #1478: URL: https://github.com/apache/rocketmq-clients/issues/1478
### Before Creating the Bug Report - [x] I found a bug, not just asking a question, which should be created in [GitHub Discussions](https://github.com/apache/rocketmq-clients/discussions). - [x] I have searched the [GitHub Issues](https://github.com/apache/rocketmq-clients/issues) and [GitHub Discussions](https://github.com/apache/rocketmq-clients/discussions) of this repository and believe that this is not a duplicate. - [x] I have confirmed that this bug belongs to the current repository, not other repositories of RocketMQ. ### Programming Language of the Client Rust ### Runtime Platform Environment macOS 26 (Darwin 25.6.0), arm64 ### RocketMQ Version of the Client/Server Client: Rust `rocketmq` 5.0.0, master `7fc6b1f8` Server: none needed; the reproduction below uses a local peer that accepts the connection and never answers. ### Run or Compiler Version rustc 1.97.1 ### Describe the Bug Creating the session of an endpoint has no upper bound when the endpoint accepts the connection but never answers. `ClientOption::timeout` does not apply to it. `SessionManager::get_or_create_session` calls `Session::new` (bounded by the connect timeout) and then `session.start`, which awaits `self.stub.telemetry(request)` in `establish_telemetry_stream`. That request is signed with `sign_without_timeout` on purpose, because a `grpc-timeout` would end the long-lived stream. As a side effect, waiting for the response headers of the telemetry call is not bounded either. This applies to every first RPC to an endpoint: `Producer::start`, and `send` / `receive` / route queries after a session was evicted (heartbeat failures, `clear_dead_and_idle_sessions`) or when a route points to a new endpoint. While it waits, the session map lock is held, so other RPCs queue behind it. #1448 / #1454 make the lock per endpoint, which keeps other endpoints responsive, but the callers of this endpoint still wait without a bound. ### Steps to Reproduce `Cargo.toml`: ```toml [dependencies] rocketmq = { git = "https://github.com/apache/rocketmq-clients", rev = "7fc6b1f87e4da99314b077b8f0ae7dc1cae074a4" } tokio = { version = "1", features = ["full"] } h2 = "0.4" ``` `src/main.rs`: ```rust use rocketmq::conf::{ClientOption, ProducerOption}; use rocketmq::Producer; use std::time::{Duration, Instant}; use tokio::net::TcpListener; // Accepts TCP connections, never speaks HTTP/2. async fn silent_tcp(listener: TcpListener) { let mut held = Vec::new(); loop { held.push(listener.accept().await.unwrap().0); } } // Speaks HTTP/2 (acks SETTINGS and PING) but never answers any RPC. async fn silent_h2(listener: TcpListener) { loop { let (sock, _) = listener.accept().await.unwrap(); tokio::spawn(async move { let Ok(mut conn) = h2::server::handshake(sock).await else { return }; let mut held = Vec::new(); while let Some(Ok(stream)) = conn.accept().await { held.push(stream); } }); } } async fn run(name: &str, addr: String, guard: Duration) { let mut client_option = ClientOption::default(); client_option.set_access_url(addr); client_option.set_timeout(Duration::from_secs(3)); let mut producer_option = ProducerOption::default(); producer_option.set_topics(vec!["parent".to_string()]); let mut producer = Producer::new(producer_option, client_option).unwrap(); let started = Instant::now(); match tokio::time::timeout(guard, producer.start()).await { Err(_) => println!("{name}: still pending after {:?}", started.elapsed()), Ok(r) => println!( "{name}: returned after {:?}: {:?}", started.elapsed(), r.map(|_| "ok").map_err(|e| e.to_string()) ), } } #[tokio::main] async fn main() { let guard = Duration::from_secs(150); let a = TcpListener::bind("127.0.0.1:0").await.unwrap(); let b = TcpListener::bind("127.0.0.1:0").await.unwrap(); let (aa, ba) = (a.local_addr().unwrap().to_string(), b.local_addr().unwrap().to_string()); tokio::spawn(silent_tcp(a)); tokio::spawn(silent_h2(b)); tokio::join!(run("silent_tcp", aa, guard), run("silent_h2", ba, guard)); } ``` Then `cargo run`. ### What Did You Expect to See? `Producer::start` returns an error after about `ClientOption::timeout` (3 s here) in both cases, like other RPCs. ### What Did You See Instead? ``` silent_tcp: returned after 90.007839458s: Err("Client internal error at client.start, context: { called: session.start } => send rpc telemetry failed, source: status: Unavailable, message: \"http2 error: keep-alive timed out\", details: [], metadata: MetadataMap { headers: {} }") silent_h2: still pending after 150.009368s ``` The first case is only ended by HTTP/2 keep-alive (`KEEP_ALIVE_INTERVAL` 60 s + `KEEP_ALIVE_TIMEOUT` 30 s). In the second case the peer answers PINGs, so keep-alive never fires and the call waits forever. The 150 s is just the guard in the reproduction. ### Additional Context A possible fix: bound only the wait for the response of the telemetry call, not the stream itself, for example ```rust let response = tokio::time::timeout(*self.option.timeout(), self.stub.telemetry(request)) .await .map_err(|_| /* ErrorKind::ClientInternal or a timeout kind, OPERATION_START */)? .map_err(|e| /* as today */)?; ``` so that the stream stays long-lived once established. `Session::reconnect` and `Session::update_settings` call `establish_telemetry_stream` as well and would be bounded by the same change. Related: #1448, #1454 (lock granularity; they do not add a bound on this wait). -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
