Skip to content

Fix stray control bytes tearing down the ASTM connection#79

Merged
ramonski merged 2 commits into
2.xfrom
harden-astm-stray-control
Jun 9, 2026
Merged

Fix stray control bytes tearing down the ASTM connection#79
ramonski merged 2 commits into
2.xfrom
harden-astm-stray-control

Conversation

@xispa

@xispa xispa commented Jun 4, 2026

Copy link
Copy Markdown
Member

Description of the issue/feature this PR addresses

Follow-up to #77 (chunked-frame reassembly). Raising inside an asyncio protocol's data_received() is fatal -- it drops the connection. Several ASTM handlers raised on input that instruments legitimately send, so a single stray byte forced a disconnect/reconnect even when framing was fine:

  • on_eot() raised InvalidState when an <EOT> arrived outside a transfer, but instruments emit stray <EOT> (and <EOT>/<ENQ> bursts) between sessions and while establishing.
  • on_ack()/on_nak() raised NotAccepted on any <ACK>/<NAK>; as the receiver we should ignore these.

Observed live against an Abbott ARCHITECT ci4100: after #77 made frames reassemble correctly, <EOT>/<ENQ> bursts between sessions still crashed the connection repeatedly (disconnect + reconnect churn).

Current behavior before PR

A stray <EOT> outside a transfer, or any <ACK>/<NAK>, raises inside data_received() and tears down the connection, forcing a reconnect. One unexpected byte can interrupt an otherwise healthy link.

Desired behavior after PR is merged

Stray/unexpected control bytes are non-fatal: on_eot() outside a transfer and unexpected on_ack()/on_nak() log-and-ignore, and the unit-dispatch loop wraps handle_data() in try/except so no single byte can drop the link. The stray-<EOT> branch does not call reset_session_state() (that would clear the buffer mid-dispatch and drop bytes following the EOT in the same read). Adds tests for stray <EOT>, <EOT>/<ENQ> bursts, an <EOT>+<ENQ> in one read, and unexpected <ACK>/<NAK>.

--
I confirm I have tested this PR thoroughly and coded it according to PEP8
and Plone's Python styleguide standards.

@ramonski ramonski force-pushed the harden-astm-stray-control branch from 5918546 to 7a7d64d Compare June 9, 2026 20:54
@ramonski ramonski merged commit 4affbe8 into 2.x Jun 9, 2026
2 checks passed
@ramonski ramonski deleted the harden-astm-stray-control branch June 9, 2026 20:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants