Panic: Unwrapping send on closed report channel causes ReceiveClosed in worker tasks under load
评估
调研方向
从 src/client.rs 的 1245–1250 行附近开始,跟踪提前关闭期间 report channel 的 receiver 生命周期。审查其他 worker/reporting 路径,查找 issue 中提到的 send(...).unwrap() 调用。完成的标准是已关闭的 receiver 不再导致 worker panic,包括在提供的高并发复现中。
由索引模型根据 Issue 内容生成。
描述
Summary
When running oha with high concurrency (e.g. -n 5000 -c 1000) and especially with --latency-correction enabled, worker tasks can panic with:
panic at src/client.rs:1254:49: called `Result::unwrap()` on an `Err` value: ReceiveClosed
Reproduction
Run:
oha 'http://localhost:9000/api/requests/' -n 5000 -c 1000 -m POST --latency-correction -H 'Content-Type: application/json' -d '{"email":"[email protected]"}'
The panic is much more likely at high concurrency or when early shutdown occurs. It is triggered when the result receiver closes before all worker tasks finish.
Root cause
Code at src/client.rs:1245-1250:
while counter.fetch_add(1, Ordering::Relaxed) < n_tasks {
let res = client.work_http1(&mut client_state).await;
let is_cancel = is_cancel_error(&res);
report_tx.send(res).unwrap();
if is_cancel { break; }
}
When the receiver is closed (for example, when test duration or parent task completes), further sends panic workers via .unwrap().
Impact
This is a race between result reporting and the receiver's lifetime. In normal or high-pressure use, fast termination of the receiver (parent) leaves workers panicking on .unwrap() if they race to send results after closed.
Possible solutions
- Change all
report_tx.send(...).unwrap();sites to handle channel closure gracefully, e.g.:if report_tx.send(res).is_err() { break; } - Prefer
ok()and silent exit when the receiver is gone, since there's nothing further the worker can do. - Audit all other worker/reporting codepaths for
send(...).unwrap()(other than in tests) and apply similar fix.
Let me know if you need details or logs would be useful.
- 主要语言
- Rust
- 星标
- 10.7k
- 派生
- 311
- 平均合并
- 24 分钟
- 30 天内合并 PR
- 6
环境准备
- 提供 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 没有贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
hatoo/oha 的其他 Issue
-
难度 2/5 半天 新手友好度 62/100
-
难度 4/5 3-5 天 新手友好度 28/100
-
难度 4/5 3-5 天 新手友好度 35/100
-
HTTP/3 very slow未关闭
难度 4/5 3-5 天 新手友好度 45/100
-
难度 4/5 3-5 天 新手友好度 38/100
相似的 Issue
-
marketing
难度 2/5 1-3 小时 新手友好度 82/100
维护者通常 1 天内回复
-
help wanted small extra
难度 2/5 1-3 小时 新手友好度 70/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 62/100
n0-computer/net-tools#282 ·
维护者通常 2 天内回复
-
难度 2/5 1-3 小时 新手友好度 84/100
eliasstravik/herdr-projects#1551 ·