Panic: Unwrapping send on closed report channel causes ReceiveClosed in worker tasks under load

未关闭
#883 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

@tyr1k 已经在做这个了。

开始于 2026年6月5日。

  • #885 来自 @tyr1k —— 未关闭
  • #907 来自 @Golopmoui3 —— 未关闭

评估

难度
3/5
预计耗时
1-2 天
新手友好度
68/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
冷清
技术栈
rust
领域
cli

调研方向

从 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 模板
  • 没有贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

hatoo/oha 的其他 Issue

查看 hatoo/oha 的全部 Issue

相似的 Issue

更多 Rust Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。