[MXA-001] Alarm failover never engages when wnwrap primary fails to subscribe (PollOnce no-op resets counter) #249

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

MXA-001: Alarm failover never engages (or falsely "recovers") when the wnwrap primary fails to subscribe

  • Severity: High
  • Category: Bug
  • Confidence: Confirmed (code path); not run against live wnwrap
  • Locations:
    • MxAccess/WnWrapAlarmConsumer.cs:355-363 (PollOnce returns silently when !subscribed)
    • MxAccess/WnWrapAlarmConsumer.cs:188-281 (subscribed = true only at the end of Subscribe)
    • MxAccess/FailoverAlarmConsumer.cs:137-157 (Subscribe), :291-309 (RunPrimary), :223-259 (ProbeOnce)
    • MxAccess/AlarmCommandHandler.cs:253-257 (default threshold 3, stable probes 3)

Description. FailoverAlarmConsumer.Subscribe routes the primary's Subscribe through RunPrimary, which swallows the exception and counts one failure. WnWrapAlarmConsumer.Subscribe sets subscribed = true only after all four wnwrap calls succeed, so after a failure it stays false. From then on WnWrapAlarmConsumer.PollOnce returns at if (disposed || !subscribed) return; without touching COM. RunPrimary treats that silent return as success and resets consecutiveFailures to 0. ProbeOnce treats it as a clean probe. Nothing ever re-subscribes the primary (ProbeOnce deliberately does not).

Failure scenario.

  • Default threshold (3): the alarm manager is unavailable when SubscribeAlarms runs, so InitializeConsumer/RegisterConsumer/Subscribe return non-zero or SetXmlAlarmQuery throws. That is failure 1 of 3. Every later poll is a no-op "success", so the counter never reaches 3. The consumer stays in Alarmmgr mode with a dead primary: no transitions, an empty QueryActiveAlarms snapshot, no OnAlarmProviderModeChanged, and no fault. The subtag standby is armed but gated off.
  • Threshold 1: the subscribe failure switches to standby. After FailbackStableProbes no-op probes (about 90 s at the defaults) the consumer announces "recovered" and switches back to the dead primary. The gateway then reconciles against an empty snapshot and clears every alarm the standby had reported.

The unit tests miss this because the fake primary in FailoverAlarmConsumerTests throws from PollOnce while unhealthy; the production consumer does not.

Suggested fix. Make an unsubscribed primary count as unhealthy: either have WnWrapAlarmConsumer.PollOnce throw when Subscribe was attempted and failed, or have FailoverAlarmConsumer track primarySubscribed and retry primary.Subscribe in PollOnce/ProbeOnce (counting failures) instead of polling. A failed subscribe needs wnwrap deregistered first, or a fresh consumer instance.

Test idea. A primary fake whose Subscribe throws and whose PollOnce is a no-op (the wnwrap shape). Assert that after Threshold poll ticks the mode is Subtag, and that ProbeOnce never fails back until a Subscribe succeeds.


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.

### MXA-001: Alarm failover never engages (or falsely "recovers") when the wnwrap primary fails to subscribe - **Severity:** High - **Category:** Bug - **Confidence:** Confirmed (code path); not run against live wnwrap - **Locations:** - `MxAccess/WnWrapAlarmConsumer.cs:355-363` (`PollOnce` returns silently when `!subscribed`) - `MxAccess/WnWrapAlarmConsumer.cs:188-281` (`subscribed = true` only at the end of `Subscribe`) - `MxAccess/FailoverAlarmConsumer.cs:137-157` (`Subscribe`), `:291-309` (`RunPrimary`), `:223-259` (`ProbeOnce`) - `MxAccess/AlarmCommandHandler.cs:253-257` (default threshold 3, stable probes 3) **Description.** `FailoverAlarmConsumer.Subscribe` routes the primary's `Subscribe` through `RunPrimary`, which swallows the exception and counts one failure. `WnWrapAlarmConsumer.Subscribe` sets `subscribed = true` only after all four wnwrap calls succeed, so after a failure it stays `false`. From then on `WnWrapAlarmConsumer.PollOnce` returns at `if (disposed || !subscribed) return;` without touching COM. `RunPrimary` treats that silent return as success and resets `consecutiveFailures` to 0. `ProbeOnce` treats it as a clean probe. Nothing ever re-subscribes the primary (`ProbeOnce` deliberately does not). **Failure scenario.** - Default threshold (3): the alarm manager is unavailable when `SubscribeAlarms` runs, so `InitializeConsumer`/`RegisterConsumer`/`Subscribe` return non-zero or `SetXmlAlarmQuery` throws. That is failure 1 of 3. Every later poll is a no-op "success", so the counter never reaches 3. The consumer stays in `Alarmmgr` mode with a dead primary: no transitions, an empty `QueryActiveAlarms` snapshot, no `OnAlarmProviderModeChanged`, and no fault. The subtag standby is armed but gated off. - Threshold 1: the subscribe failure switches to standby. After `FailbackStableProbes` no-op probes (about 90 s at the defaults) the consumer announces "recovered" and switches back to the dead primary. The gateway then reconciles against an empty snapshot and clears every alarm the standby had reported. The unit tests miss this because the fake primary in `FailoverAlarmConsumerTests` throws from `PollOnce` while unhealthy; the production consumer does not. **Suggested fix.** Make an unsubscribed primary count as unhealthy: either have `WnWrapAlarmConsumer.PollOnce` throw when `Subscribe` was attempted and failed, or have `FailoverAlarmConsumer` track `primarySubscribed` and retry `primary.Subscribe` in `PollOnce`/`ProbeOnce` (counting failures) instead of polling. A failed subscribe needs wnwrap deregistered first, or a fresh consumer instance. **Test idea.** A primary fake whose `Subscribe` throws and whose `PollOnce` is a no-op (the wnwrap shape). Assert that after `Threshold` poll ticks the mode is `Subtag`, and that `ProbeOnce` never fails back until a `Subscribe` succeeds. --- 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:workerpriority: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.

Subscribe failure counts as a failure; recovery subscribes a fresh wnwrap instance and fails back only after success. Live rig check not run (rig alarms are object-driven).

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. Subscribe failure counts as a failure; recovery subscribes a fresh wnwrap instance and fails back only after success. Live rig check not run (rig alarms are object-driven).
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: dohertj2/mxaccessgw#249