Driver health is published AFTER teardown, so GetHealth() can report Healthy with a disposed client #517

Open
opened 2026-07-27 13:52:03 -04:00 by dohertj2 · 0 comments
Owner

Found in the MTConnect Task 9 code review (PR #506), deliberately not fixed there because MTConnect follows the existing fleet convention — fixing one driver alone would create inconsistency.

Symptom

GetHealth() can report Healthy while the driver's client is already disposed.

Cause

ShutdownAsync and the InitializeAsync failure path both await TeardownCoreAsync() — disposing the client and clearing state — before calling WriteHealth(...). A GetHealth() landing in that window observes the stale, pre-teardown health value.

This is a fleet-wide ordering pattern, not an MTConnect regression: ModbusDriver.cs:247-249 has the identical teardown-then-write sequence.

Suggested fix

A fleet-wide pass: write a transitional / Degraded health value before disposing, so the race window leans conservative rather than optimistic. Audit every driver for the same ordering while doing it.

Found in the MTConnect Task 9 code review (PR #506), deliberately not fixed there because MTConnect follows the existing fleet convention — fixing one driver alone would create inconsistency. ## Symptom `GetHealth()` can report **Healthy** while the driver's client is already disposed. ## Cause `ShutdownAsync` and the `InitializeAsync` failure path both `await TeardownCoreAsync()` — disposing the client and clearing state — **before** calling `WriteHealth(...)`. A `GetHealth()` landing in that window observes the stale, pre-teardown health value. This is a fleet-wide ordering pattern, not an MTConnect regression: `ModbusDriver.cs:247-249` has the identical teardown-then-write sequence. ## Suggested fix A fleet-wide pass: write a transitional / `Degraded` health value **before** disposing, so the race window leans conservative rather than optimistic. Audit every driver for the same ordering while doing it.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: dohertj2/lmxopcua#517