Skip to content

fix(client): handle closed report channel gracefully without panic (fixes #883) - #907

Open
Golopmoui3 wants to merge 2 commits into
hatoo:masterfrom
Golopmoui3:fix/issue-883-worker-panic
Open

Golopmoui3 wants to merge 2 commits into
hatoo:masterfrom
Golopmoui3:fix/issue-883-worker-panic

Conversation

@Golopmoui3

Copy link
Copy Markdown

Summary

Fixes #883.

This PR fixes a worker panic (called Result::unwrap() on an Err value: ReceiveClosed) that occurs when running oha under high concurrency or when the report receiver channel closes early (e.g., deadline reached, early cancellation, or parent task termination).

Problem

In src/client.rs and src/client_h3.rs, worker tasks sent their request results through report_tx with an unconditional .unwrap():

report_tx.send(res).unwrap();

When the receiver task terminates early or the channel receiver drops before all worker threads complete, subsequent send attempts return Err(ReceiveClosed). Due to .unwrap(), this caused worker tasks to panic and abort unexpectedly.

Changes

  1. Safe worker loop termination:
    • Replaced unconditional .unwrap() on report_tx.send(...) calls across src/client.rs and src/client_h3.rs.
    • When report_tx.send(res).is_err(), workers now terminate cleanly by breaking out of their loops or returning early.
    • Updated work_http2_once and work_http3_once to propagate channel disconnection as task cancellation (is_cancel || is_closed).
    • Discard send errors in fast mode and deadline handlers where receiver teardown may race with final batch delivery.
  2. Regression Testing:
    • Added unit test test_work_does_not_panic_on_closed_receiver in src/client.rs. The test drops the receiver immediately before launching workers and verifies they exit cleanly without panicking.

Verification

  • cargo test --bin oha: 42/42 tests passing.
  • cargo clippy -- -D warnings: 0 warnings, clean lint check.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants