Merge #989: MTConnect condition last-wins in /sample, subscription release on shutdown, restart re-baseline, parser skips bad observations, subscribe/unsubscribe races

This commit is contained in:
Joseph Doherty
2026-12-03 10:16:27 -05:00
10 changed files with 643 additions and 40 deletions
+19 -1
View File
@@ -678,7 +678,7 @@ deliberately different, kept.
| Component nesting bound 64 (`MAX_COMPONENT_DEPTH`) | covered | `MTConnectProbeParser.MaxComponentDepth` · `MTConnectProbeParseTests` |
| Streams element nesting bound 64 (`MAX_ELEMENT_DEPTH`) | **gap → closed** — the walk recursed without bound: an uncatchable `StackOverflowException`, i.e. a server-process crash | `MTConnectStreamsParser.MaxElementDepth` · `Streams_parse_refuses_absurd_nesting_…`, controls `Streams_parse_accepts_ordinary_device_nesting`, `An_absurdly_deep_error_document_still_yields_the_agents_words` |
| Structural elements under `<Components>`/`<Devices>` skipped (`NOT_A_COMPONENT`) | **gap → closed** (one stray `<Description>` failed the whole probe) | `MTConnectProbeParser.ComponentLikeChildren` · `A_structural_element_under_components_or_devices_is_skipped_not_fatal` |
| Malformed XML, missing header, missing `dataItemId` throw | covered | `Probe_parse_throws_on_malformed_xml`, `Parse_throws_on_malformed_xml`, `Parse_throws_on_a_malformed_observation` |
| Malformed XML and a missing/unusable `<Header>` throw; a malformed OBSERVATION (no `dataItemId`, no/unparseable `timestamp`) is **skipped + counted** (#989 M-8 — it used to throw, so one bad adapter item failed every chunk, re-baseline and finally `InitializeAsync`; `MTConnectStreamsResult.SkippedObservations`/`FirstSkipReason`, one Warning per client) | covered | `Probe_parse_throws_on_malformed_xml`, `Parse_throws_on_malformed_xml`, `Parse_skips_a_malformed_observation_and_keeps_the_rest_of_the_document`, `CurrentAsync_survives_one_malformed_observation_and_warns_once` |
| BOM / framing whitespace tolerated on a chunk | covered | `Parse_from_bytes_tolerates_the_multipart_frames_trailing_line_break` |
| Multipart framing: Content-length authoritative, boundary-scan fallback, preamble, LF-only, split reads, truncation throws, 32 MiB part cap (`MTConnectMultipartReader`) | covered | `MultipartStreamReader` · `SampleAsync_frames_*`, `A_part_without_content_length_warns_once…`; Java cases ported as `A_declared_content_length_is_authoritative…`, `A_preamble_is_skipped_and_line_feed_only_framing_is_accepted`, `A_part_shorter_than_its_declared_content_length_is_a_lost_stream`, `A_part_larger_than_the_buffer_cap_is_refused` |
| Typed Device → Component → DataItem tree; `name` else `id`; leaf ref = DataItem id (`MTConnectBrowseTree`) | covered | `DiscoverAsync`/`StreamContainer` · `MTConnectDiscoverTests` |
@@ -834,6 +834,24 @@ NodeIds moved together in every leg. Fixture containers were restored healthy af
| Genuine buffer overrun | A stalling TCP proxy froze the driver's transport while 32 000 observations were injected (`AllowPut`) — the Agent's `firstSequence` passed the driver's cursor (75 856 → 77 083). On release the resume was refused `OUT_OF_RANGE`, the driver re-baselined from `/current` within 1 s and resumed; values Good, no restart misdiagnosed. A raised-count stream (count 16, interval 5 s) was **not** lapped by a 266 obs/s burst: chunks are sent back-to-back while data is pending, so `interval` does not cap throughput. |
| `SampleCount` vs `bufferSize` (#825) | Test Connect rendered the amber "OK with warning" chip and a deploy logged the Warning (`/hosts` shows `agentBufferSize`). The same gate measured the Agent's real edge — `count = 16384` streams, `16385` is `OUT_OF_RANGE` — so the first build's "at or above" threshold was corrected to "above" (pinned live by `Test_Connect_warns_when_SampleCount_exceeds_the_live_agents_buffer_size`). |
## Review 2026-12-02 fixes (#989)
- **M-4 — condition word on a value tag.** Worst-of-states (Fault beats Warning beats Normal) applies only to a `/current`
baseline, where several states are simultaneously active, and only to CONDITION observations. A `/sample` chunk is a
time-ordered delta, so it is last-wins: Fault then Normal reads Normal, Fault then UNAVAILABLE reads
`BadNoCommunication`. (The native-alarm path never had the problem — `MTConnectConditionTracker`.)
- **M-5 — subscription leak.** `ShutdownAsync` releases every data and alarm subscription. The host actor abandons its
handles on each reconnect/Force Reconnect and re-subscribes after the next init, so the old registrations used to pile up
(one per cycle: an extra callback per observation and a pump that never stopped). `InitializeAsync` deliberately does
not clear (subscribe-before-initialize is a contract) and `ReinitializeAsync` keeps standing subscriptions.
- **M-7 — read-path restart.** A `ReadAsync` that sees a new Agent `instanceId` with no pump running re-baselines the
shared index and condition tracker from that `/current` (it already advanced the cursor, so no pump chunk would).
- **M-9 — initial replay.** After raising the initial replay, `SubscribeAsync` re-reads the index and re-raises anything
the pump pushed meanwhile (bounded), so a late stale replay cannot leave the node on an old value. (The MQTT half of M-9
is tracked separately.)
- **M-10 — unsubscribe vs subscribe.** The stream stop re-checks for subscribers in the same critical section that
detaches the pump, so a concurrent subscribe keeps its pump.
## Known limitations
These are real, not placeholders — read them before relying on the driver