fix(heidenhain): #990 review — host-facing state keyed by host:port survives re-init; dispose cancels before closing the session

- _facing was keyed by runtime instance: it grew one entry per re-init (watchdog every ~90 s
  while a control is down) and each new runtime restarted at Unknown, so a down control's
  status flapped Stopped -> Unknown -> Stopped across every re-init. Now keyed by host:port,
  pruned to the configured hosts at init and cleared at shutdown; a runtime no longer in
  _devices (being stopped by re-init/shutdown) announces nothing.
- DeviceRuntime.DisposeAsync cancels the loop BEFORE closing the session: closing first woke
  an in-flight read while the token was live, and the loop's normal tail set Backoff (host
  Stopped) for a plain stop. Seam AfterSessionCloseForTests makes the race deterministic.
This commit is contained in:
Joseph Doherty
2026-12-03 11:55:28 -05:00
parent 7a6e623485
commit 2d28f5ea8a
4 changed files with 105 additions and 8 deletions
+5 -3
View File
@@ -440,10 +440,12 @@ overrides, axes, tool, the whole alarm walk) and aliased custom addresses are re
then drops is backed off, not re-dialled every `InitialDelayMs`. Unlike the Java base, an initial connect
failure also retries (no manual restart). The loop survives any unexpected fault (logged, retired, backed off);
JSON-`null` config sections are normalised to defaults by the parser.
(#990) A deliberate stop (deploy / Force Reconnect) is never an outage: the runtime's generation is bumped before
the session closes, and its values are invalidated. The backoff count is carried across a watchdog re-init, so a
(#990) A deliberate stop (deploy / Force Reconnect) is never an outage: the runtime's generation is bumped and its
loop CANCELLED before the session closes (closing first let a woken loop report `Backoff` — host `Stopped` — for a
plain stop), and its values are invalidated. The backoff count is carried across a watchdog re-init, so a
`MaxDelayMs` above ~90 s is reachable. While a control is down its host status stays `Stopped` (no
`Stopped`/`Unknown` flap, "since" time stable). A refused optional DNC/DATA login is retried per session on a
`Stopped`/`Unknown` flap, "since" time stable) — across a re-init too: the announced host state is kept per
`host:port` (not per runtime instance), and a runtime being stopped by a re-init announces nothing. A refused optional DNC/DATA login is retried per session on a
5 s to 5 min exponential schedule instead of on every poll batch.
- Subscriptions: the initial push and later publications are ordered under one lock, so a subscriber never
receives an older value after a newer one. A re-init disposes every control loop first; a late start of a