[SEC-005] Alarm monitor restart drops cache without Clear/provider-status frames; cleared alarms stay active downstream #250

Closed
opened 2026-12-02 16:07:36 -05:00 by dohertj2 · 1 comment
Owner

SEC-005 — Monitor restart silently drops the cache; subscribers keep stale alarms

  • Severity: High · Category: Bug · Confidence: Confirmed
  • Location: Alarms/GatewayAlarmMonitor.cs:330-342 (finally → ClearCache), 1007-1020, 237-245, 884-937.

Description. StreamAsync subscribers deliberately outlive the monitor's worker session. When a lifecycle ends (worker crash, lease overflow, command failure) ClearCache empties _alarms with no Clear broadcast. After the restart the first ApplyReconcile diffs the new snapshot against the empty cache, so it emits only Raise repairs. An alarm that cleared while the monitor was down is in neither set and gets no Clear. Separately, the lifecycle start re-baselines _providerMode/_providerDegraded/_providerReason (lines 237-245) without BroadcastToAll.

Failure scenario. OtOpcUa holds a StreamAlarms stream. Alarm Galaxy!Area.Tank01.HiHi is active. The worker faults; the monitor restarts after 5 s plus worker startup. The alarm returns to normal during that gap. The new reconcile does not contain it, the cache is already empty, and no Clear is ever sent. OtOpcUa shows the alarm active until its own stream reconnects, which may be never. Likewise a subscriber that last saw Subtag / degraded keeps showing degraded after the restart lands back on the alarm manager, because Auto mode raises no mode-change event at start.

Suggested fix. Keep the previous generation for diffing instead of clearing it (hide it from CurrentAlarms while not Monitoring), so the first reconcile of the new lifecycle emits the missing Clears. Alternatively broadcast Clear for every cached alarm in ClearCache. Broadcast the provider status after the re-baseline.

Test idea. Fake session manager: reconcile returns {A, B}; attach a subscriber; end the event stream to force a restart; second lifecycle's reconcile returns {A}. Assert the subscriber receives Clear for B. Second test: assert a ProviderStatus frame after a restart from Subtag.


Source: code-reviews/2026-12-02-perf-bugs/README.md and code-reviews/2026-12-02-perf-bugs/PLAN.md (commit f200bda6 on local branch docs/review-2026-12-02-perf-bugs, not yet pushed). Reviewed at 54367e74.

## SEC-005 — Monitor restart silently drops the cache; subscribers keep stale alarms - **Severity:** High · **Category:** Bug · **Confidence:** Confirmed - **Location:** `Alarms/GatewayAlarmMonitor.cs:330-342` (finally → `ClearCache`), `1007-1020`, `237-245`, `884-937`. **Description.** `StreamAsync` subscribers deliberately outlive the monitor's worker session. When a lifecycle ends (worker crash, lease overflow, command failure) `ClearCache` empties `_alarms` with no `Clear` broadcast. After the restart the first `ApplyReconcile` diffs the new snapshot against the empty cache, so it emits only `Raise` repairs. An alarm that cleared while the monitor was down is in neither set and gets no `Clear`. Separately, the lifecycle start re-baselines `_providerMode/_providerDegraded/_providerReason` (lines 237-245) without `BroadcastToAll`. **Failure scenario.** OtOpcUa holds a `StreamAlarms` stream. Alarm `Galaxy!Area.Tank01.HiHi` is active. The worker faults; the monitor restarts after 5 s plus worker startup. The alarm returns to normal during that gap. The new reconcile does not contain it, the cache is already empty, and no `Clear` is ever sent. OtOpcUa shows the alarm active until its own stream reconnects, which may be never. Likewise a subscriber that last saw `Subtag / degraded` keeps showing degraded after the restart lands back on the alarm manager, because Auto mode raises no mode-change event at start. **Suggested fix.** Keep the previous generation for diffing instead of clearing it (hide it from `CurrentAlarms` while not `Monitoring`), so the first reconcile of the new lifecycle emits the missing `Clear`s. Alternatively broadcast `Clear` for every cached alarm in `ClearCache`. Broadcast the provider status after the re-baseline. **Test idea.** Fake session manager: reconcile returns {A, B}; attach a subscriber; end the event stream to force a restart; second lifecycle's reconcile returns {A}. Assert the subscriber receives `Clear` for B. Second test: assert a `ProviderStatus` frame after a restart from Subtag. --- Source: `code-reviews/2026-12-02-perf-bugs/README.md` and `code-reviews/2026-12-02-perf-bugs/PLAN.md` (commit `f200bda6` on local branch `docs/review-2026-12-02-perf-bugs`, not yet pushed). Reviewed at `54367e74`.
dohertj2 added the area:gatewaypriority:p1type:bugtype:review-finding labels 2026-12-02 16:07:36 -05:00
Author
Owner

Merged to main at 68043411 (pushed 2026-12-03). Gateway suite 1610 passed / 0 failed (macOS); windev worker CI 836 passed / 0 failed on that SHA.

Restart keeps the old cache and the first reconcile diffs against it, emitting Clear repairs + provider status (see gateway.md). DSH-005 hub priming added.

Merged to `main` at `68043411` (pushed 2026-12-03). Gateway suite 1610 passed / 0 failed (macOS); windev worker CI 836 passed / 0 failed on that SHA. Restart keeps the old cache and the first reconcile diffs against it, emitting Clear repairs + provider status (see `gateway.md`). DSH-005 hub priming added.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: dohertj2/mxaccessgw#250