recv_or_diagnose

Function recv_or_diagnose 

Source
pub fn recv_or_diagnose<T>(
    rx: &Receiver<T>,
    timeout: Duration,
    hung_msg: &str,
    panicked_msg: &str,
) -> T
Expand description

Receive one value from a watchdogged worker, or panic with the diagnosis that actually fits what happened.

recv_timeout returns Err for BOTH Timeout and Disconnected, so a harness that tests is_ok() — or collapses the two Err arms into one — reports a worker PANIC as a hang. That is a confident wrong diagnosis: it sends the reader after a termination guard that is working fine, while the real panic scrolls past unread (#2945).

The two states therefore get two messages, chosen by the caller:

  • Timeout — nothing arrived and the sender is still alive: a real hang. Panics with hung_msg.
  • Disconnected — the sender was dropped without sending, which for these suites means the worker unwound. Panics with panicked_msg.

The match is exhaustive by variant with no wildcard arm, so a future third RecvTimeoutError state fails to compile here rather than being silently folded into one of the existing diagnoses.

Note the honest limit of Disconnected: it says the sender is gone, not why. A worker that returns early without sending is reported as a panic. Every caller here sends on its last line, so the two coincide.