From 5079d33b0a020e321fad82b5ac1e6a4fbbc1424f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=83=91=E5=8D=9A=E6=96=87?= <1323515022@qq.com> Date: Fri, 30 Oct 2026 10:38:04 +0800 Subject: [PATCH] =?UTF-8?q?fix(agent):=20=E6=98=BE=E5=BC=8F=20max=5Fidle?= =?UTF-8?q?=5Ftimeout=3D10s=E2=80=94=E2=80=94=E5=BC=BA=E6=9D=80=E4=B8=BB?= =?UTF-8?q?=E6=8E=A7=E7=AB=AF=E5=90=8E=2010=20=E7=A7=92=E5=86=85=E5=8F=AF?= =?UTF-8?q?=E9=87=8D=E8=BF=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 问题(实测复现) 串行 accept 下,主控端被强杀(force-stop,非正常 close)时 QUIC 连接 不会立即消亡:agent 还在向死连接发帧,新连接只能排队,要等 quinn 默认 idle 超时(约 30s)才能建立。表现为「杀掉 App 重开,一直连不上」。 修法 TransportConfig 显式设 max_idle_timeout=10s。正常会话每 500ms 一个 Ping 永不触发该超时,只回收死连接。10s = 20 个 Ping 周期,抗抖动余量足够。 验证(vivo S6 实测) - 会话1 auth ok -> force-stop App -> 立即重连 - 10.2s 后 peer connected + auth ok(修复前 ~30s) --- agent/src/main.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/agent/src/main.rs b/agent/src/main.rs index 837f135..cffe7d0 100644 --- a/agent/src/main.rs +++ b/agent/src/main.rs @@ -53,6 +53,14 @@ async fn main() -> Result<()> { transport.receive_window(quinn::VarInt::from_u32(16 * 1024 * 1024)); transport.stream_receive_window(quinn::VarInt::from_u32(8 * 1024 * 1024)); transport.send_window(64 * 1024); + // 空闲超时:主控端被强杀(非正常 close)时收不到它的 Ping,连接会一直占住 + // 串行 accept,下一个连接要等几十秒才能建立。10s = 20 个 Ping 周期, + // 正常会话(Ping 每 500ms)永不触发,只用来回收死连接。 + transport.max_idle_timeout(Some( + Duration::from_secs(10) + .try_into() + .expect("10s fits in VarInt"), + )); let mut server_config = quinn::ServerConfig::with_single_cert(vec![cert], key.into())?; server_config.transport_config(Arc::new(transport));