fix(client): #1048 Client.UI recursive subscribe + restore batch through SubscribeManyAsync; CLI subscribe/alarms exit 3 when a failover never recovers

- SubscriptionsViewModel collects the subtree's variables first (deduped, already-subscribed
  skipped) and creates them in one SubscribeManyAsync; per-node failures are named in
  StatusMessage, a whole-batch failure adds nothing. RestoreSubscriptionsAsync batches too.
- CLI: ConnectionLossWatch ends subscribe/alarms when the service lands Disconnected on its
  own, or stays out of Connected past --reconnect-timeout (default 300 s, 0 = no limit):
  WARNING line, summary (subscribe adds 'Connection: LOST'), exit code 3. A recovery inside
  the window re-arms the watch.
This commit is contained in:
Joseph Doherty
2026-12-03 15:07:30 -05:00
parent 65212dd471
commit 9496db9357
10 changed files with 471 additions and 37 deletions
+6
View File
@@ -71,6 +71,10 @@ When `-F` is provided, the shared service tries the primary URL first, then each
If every endpoint is down when a failover starts (a restarting server, a redundant partner mid-switchover) the service stays in `Reconnecting` and cycles the endpoint list again with a capped backoff (1 s doubling to 15 s) until one connects or the user disconnects; it never gives up on its own (#1000). Both commands print `CONNECTION <old> -> <new> (<endpoint>)` lines for every transition, so a run across a restart shows the drop and the recovery. On recovery all recorded subscriptions are re-created in one batched request per sampling interval, and `subscribe` itself creates its monitored items for the whole target set (including `-r`) in one request instead of one round trip per node.
The commands themselves do not wait forever, though (#1048): if the connection stays out of `Connected` for
`--reconnect-timeout` seconds (default 300) they print a `WARNING`, the summary and exit with code **3**, so a
scripted live gate across an outage that never ends fails instead of hanging and reporting pre-outage values as final.
```bash
otopcua-cli connect -u opc.tcp://localhost:4840/OtOpcUa -F opc.tcp://localhost:4841/OtOpcUa
```
@@ -193,6 +197,7 @@ otopcua-cli subscribe -u opc.tcp://localhost:4840 -n "ns=3;s=ZB" -r --max-depth
| `-q` / `--quiet` | Suppress per-update output; only print the final summary |
| `--duration` | Auto-exit after N seconds and print the summary (0 = run until Ctrl+C, default: 0) |
| `--summary-file` | Also write the summary to this file path on exit |
| `--reconnect-timeout` | Seconds a lost connection may stay unrecovered before the command prints `WARNING: … did not recover …`, its summary (with a `Connection: LOST` line — the last values predate the loss) and exits with code **3** (default: 300; `0` = wait indefinitely). The service giving up (`Disconnected`) always ends the run with code 3 (#1048). |
#### Summary buckets
@@ -384,6 +389,7 @@ otopcua-cli alarms -u opc.tcp://localhost:4840/OtOpcUa \
| `-n` / `--node` | Node ID to monitor for events (default: Server node) |
| `-i` / `--interval` | Publishing interval in milliseconds (default: 1000) |
| `--refresh` | Request a `ConditionRefresh` after subscribing to get current retained alarm states |
| `--reconnect-timeout` | Same as `subscribe`: exit with code 3 and a `WARNING` line when a lost connection has not recovered after N seconds (default: 300; `0` = wait indefinitely), or at once if the service gives up (#1048) |
The active/acknowledged columns come from the standard `ActiveState/Id`, `AckedState/Id` and
`EnabledState/Id` event fields. Before the 2026-10 fix the client's filter selected them with a single
+1 -1
View File
@@ -85,7 +85,7 @@ Right-click on tree nodes to access:
| Action | Description |
|--------|-------------|
| **Subscribe** | Subscribe to data changes on the selected node(s). For Object nodes, recursively subscribes all Variable descendants (up to 10 levels deep). Switches to the Subscriptions tab. |
| **Subscribe** | Subscribe to data changes on the selected node(s). For Object nodes, recursively subscribes all Variable descendants (up to 10 levels deep) — the subtree is browsed first and every monitored item is then created in one batched request (#1048), with per-node failures named in the status bar. Restoring saved subscriptions at connect is batched the same way. Switches to the Subscriptions tab. |
| **View History** | Set the selected Variable node as the target in the History tab and switch to it. Only enabled for Variable nodes. |
| **Monitor Alarms** | Stop any active alarm subscription and subscribe to alarm events on the selected node. Switches to the Alarms tab with automatic condition refresh. |