Skip to content

RpcClient.send lets serial write failures through as bare RuntimeError #4191

Closed

Description

@zackees

PyserialMonitor.write converts serial.SerialException into RuntimeError("Serial write error: ...") (ci/util/pyserial_monitor.py:222). RpcClient.send retries only RpcTimeoutError (ci/rpc_client.py:437), so that RuntimeError propagates out of send unchanged — past its own documented contract, which promises RpcTimeoutError or RpcError.

Every caller that handles RPC failure by catching (RpcError, RpcTimeoutError) therefore misses a failed write. Found in _settle_link in the peer-OTA path (#4178), where it meant no retry and an error naming neither the board nor the call. Worked around there by widening that one except tuple; the general case is still open.

Why it wasn't fixed at the boundary

Normalizing inside send is the right home for it, but it is not a contained change:

  • 31 modules import RpcClient.
  • Some rely on a bare except RuntimeError to report transport failures cleanly. ci/autoresearch/decode.py:258 and :356 are the clear ones — they print Error: ... and return 1. Normalizing to RpcError (which derives from Exception, not RuntimeError) would turn those clean exits into tracebacks.

Options

  1. Make RpcError inherit from RuntimeError, then normalize in send. RpcTimeoutError already subclasses the builtin TimeoutError, so there is precedent in the same file. Existing except RuntimeError handlers keep working and existing except RpcError handlers keep working, so the normalization becomes safe everywhere. The behaviour change is that code catching RuntimeError now also catches RpcError — a widening, which is what makes it safe, but it does mean anything deliberately letting RpcError past a RuntimeError handler would change. I did not audit all 31 modules for that.

  2. Normalize in send and fix the callers. More explicit, more churn, and easy to miss one.

  3. Leave it and widen except tuples at each call site. What fix(autoresearch): name the board that failed the peer-OTA handshake (#3956) #4178 does. Works, but every caller has to know a transport detail that send should be hiding.

Option 1 looks best to me, but it touches a shared error type across the autoresearch tree, so it wants a maintainer's call rather than mine.

Reproducing

Any RPC call while the serial port drops. In a unit test:

client.send = AsyncMock(side_effect=RuntimeError("Serial write error: boom"))

against a caller catching (RpcError, RpcTimeoutError) — the error escapes.

Related: #4178, #3956.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions