OpenCyphal / pycyphal

Python implementation of the Cyphal protocol stack.
https://pycyphal.readthedocs.io/
MIT License
120 stars 105 forks source link

Assertion error in CAN transfer tracer #198

Closed pavel-kirienko closed 2 years ago

pavel-kirienko commented 2 years ago
2021-12-22 14:09:40 0012698 INF yakut.cmd.monitor: Updated in 0.033 (stats 0.008, render 0.020); dt 2.546; time lag 0.084
2021-12-22 14:09:41 0012698 ERR pyuavcan.util._broadcast: Unhandled exception in <function RedundantTransport._wrap_capture_handler.<locals>.<lambda> at 0x7fb4927f3ee0>: 
Traceback (most recent call last):
  File "/home/pavel/.local/lib/python3.8/site-packages/pyuavcan/util/_broadcast.py", line 46, in delegate
    r: typing.Union[R, Exception] = fn(*args, **kwargs)
  File "/home/pavel/.local/lib/python3.8/site-packages/pyuavcan/transport/redundant/_redundant_transport.py", line 361, in <lambda>
    return lambda cap: handler(
  File "/home/pavel/.local/lib/python3.8/site-packages/yakut/cmd/monitor/_iface.py", line 82, in _process_capture
    trace = self._tracer.update(cap)
  File "/home/pavel/.local/lib/python3.8/site-packages/pyuavcan/transport/redundant/_tracer.py", line 97, in update
    trace = tracer.update(cap.inferior)
  File "/home/pavel/.local/lib/python3.8/site-packages/pyuavcan/transport/can/_tracer.py", line 80, in update
    return self._get_session(ss).update(cap.timestamp, prio, frame)
  File "/home/pavel/.local/lib/python3.8/site-packages/pyuavcan/transport/can/_tracer.py", line 112, in update
    tr = self._reassembler.process_frame(timestamp, priority, frame, int(tid_timeout * 1e9))
  File "/home/pavel/.local/lib/python3.8/site-packages/pyuavcan/transport/can/_session/_transfer_reassembler.py", line 102, in process_frame
    assert len(fragmented_payload) > 1  # Multi-frame transfer, check and remove the trailing CRC
AssertionError
pavel-kirienko commented 2 years ago

This error can be observed when the reassembler that has just been reset is fed with the last frame of another transfer, whose TOGGLE and TRANSFER-ID happen to match the expectations of the reassembler (which happens during the full transfer-ID wraparound):

  1. Wait for the reassembler to be reset.
  2. Let: expected transfer-ID = X, expected toggle bit = Y.
  3. Construct a frame with SOF=0, EOF=1, TID=X, TOGGLE=Y.
  4. Feed the frame into the reassembler, observe the assertion failure.

Relevant context for future reference:

Screenshot_20211222_154021