fix(runtime): #1113 a stubbed driver's value nodes read BadConfigurationError, not BadWaitingForInitialData forever
Item 4. A stub child (no factory for the type, a factory that rejected the config, or a type not allowed on the node's roles) never publishes, so its nodes sat at BadWaitingForInitialData forever. StampStubbedDriverValueNodes stamps BadConfigurationError (new OpcUaStatus constant, 0x80890000) on the raw + UNS value nodes of every stubbed child after each apply's RebuildAddressSpace Tell (deploy, boot-from-cache, bootstrap restore) - same host->publish-actor pair, so the publish actor defers it behind that plan and replays it onto the nodes the apply (re)creates - and after an operator Restart into a stub. A config-change respawn into a stub gets the respawn's BadWaitingForInitialData first, then this. Status-only, not latched; a stub drops any inherited latch. Tests: Restart + config-change into a stub, and a fresh deploy of a stub (all fail with the stamp disabled).
This commit is contained in:
@@ -603,7 +603,7 @@ composition still routes for that driver (`TrimCommsLatchesToIndex`) — a ref t
|
||||
can never be re-published, so it must not be reported — and drops a latch left empty; this runs inside the same apply
|
||||
message as the respawn, so before the replacement's `Connected` can arm the audit. The Warning names the status the nodes
|
||||
actually carry: `still BadNoCommunication`, or `still BadWaitingForInitialData` once a respawn / Restart re-stamped them
|
||||
(#1113). `StopChild` also
|
||||
(#1113). A stub replacement drops the latch (it never connects, so the audit could never arm). `StopChild` also
|
||||
holds the id in the `ChildHealthLedger` (`Forget` then `Readmit` on the next spawn), so the stopped child's late health
|
||||
publish cannot resurrect its diagnostics entry.
|
||||
|
||||
@@ -649,6 +649,13 @@ supervision restart (same driver object — unchanged, still covered by that chi
|
||||
disable (`RemovedInputStatus` + node removal). ScadaBridge sees a brief Bad per respawn/Restart — accepted.
|
||||
Pinned by `DriverHostRespawnValueNodeGapTests` (both seams, both interleavings, no-latch with a positive control).
|
||||
|
||||
- **A stub replacement reads `BadConfigurationError` (#1113).** When the replacement (or a freshly deployed driver) is a
|
||||
STUB — no factory for its type on this node, the factory rejected its config, or the type is not allowed on the node's
|
||||
roles — it never publishes, so `BadWaitingForInitialData` would be a promise that cannot be kept.
|
||||
`StampStubbedDriverValueNodes` stamps `BadConfigurationError` on the raw + UNS value nodes of every stubbed child after
|
||||
each apply's `RebuildAddressSpace` Tell (deploy, boot-from-cache, bootstrap restore — on the same host→publish-actor pair,
|
||||
so the publish actor defers it behind that plan and replays it onto the nodes the apply creates or recreates; re-sent every
|
||||
apply because a rebuild resets them) and after an operator Restart that respawned a stub. Status-only, not latched.
|
||||
- **The gRPC data plane's origin side is covered by the producer fence, not by this stamp (#1113).** Projected consumers
|
||||
(DataConnectionService read / subscribe) do not read the OPC UA node state: they read the `PartitionedSampleHub`, fed
|
||||
by the driver callback through `SourceSamplePublisher`. `StopChild` / `HandleRestartDriver` call
|
||||
|
||||
@@ -58,6 +58,12 @@ public static class OpcUaStatus
|
||||
/// (lmxopcua#787) — distinct from <see cref="BadInternalError"/>, which means the tag's own script failed.</summary>
|
||||
public const uint BadOutOfService = 0x808D0000;
|
||||
|
||||
/// <summary>The source is misconfigured and will produce nothing until the configuration changes. The status a
|
||||
/// driver's value nodes carry while that driver runs as a STUB — its type has no factory on this node, the factory
|
||||
/// rejected its config, or the type is not allowed on the node's roles (lmxopcua#1113) — instead of
|
||||
/// <see cref="BadWaitingForInitialData"/>, which would promise a first value that can never come.</summary>
|
||||
public const uint BadConfigurationError = 0x80890000;
|
||||
|
||||
/// <summary>Part 4 severity bucket of <paramref name="statusCode"/>: the top two bits.</summary>
|
||||
/// <param name="statusCode">The status code to classify.</param>
|
||||
/// <returns>0 for Good, 1 for Uncertain, 2 or 3 for Bad.</returns>
|
||||
|
||||
@@ -1853,6 +1853,7 @@ public sealed partial class DriverHostActor : ReceiveActor, IWithTimers, IWithUn
|
||||
_opcUaPublishActor?.Tell(
|
||||
new ZB.MOM.WW.OtOpcUa.Runtime.OpcUa.OpcUaPublishActor.RebuildAddressSpace(correlation, deploymentId, blob, CatalogAttempt: _catalogAttempt,
|
||||
ArtifactRevision: ArtifactRevisionOf(blob)));
|
||||
StampStubbedDriverValueNodes();
|
||||
if (_opcUaPublishActor is null && _catalogAttempt is not null)
|
||||
_catalogCoordinator?.Complete(_catalogAttempt, topologySucceeded: true);
|
||||
return true;
|
||||
@@ -3628,6 +3629,8 @@ public sealed partial class DriverHostActor : ReceiveActor, IWithTimers, IWithUn
|
||||
_opcUaPublishActor?.Tell(new ZB.MOM.WW.OtOpcUa.Runtime.OpcUa.OpcUaPublishActor.RebuildAddressSpace(
|
||||
msg.Correlation, msg.DeploymentId, appliedBlob, ReportOutcome: true, CatalogAttempt: _catalogAttempt,
|
||||
ArtifactRevision: ArtifactRevisionOf(appliedBlob)));
|
||||
// #1113 item 4: after the rebuild Tell, so it is replayed onto the nodes this apply (re)creates.
|
||||
StampStubbedDriverValueNodes();
|
||||
// Reaching here means the artifact came from central, so the node is no longer serving a
|
||||
// cache-sourced configuration. Note this only clears on a real apply: a dispatch of the
|
||||
// revision already booted from cache short-circuits in HandleDispatchFromSteady without
|
||||
@@ -4333,6 +4336,7 @@ public sealed partial class DriverHostActor : ReceiveActor, IWithTimers, IWithUn
|
||||
CacheAppliedArtifact(deploymentId, rev, appliedBlob);
|
||||
_opcUaPublishActor?.Tell(new ZB.MOM.WW.OtOpcUa.Runtime.OpcUa.OpcUaPublishActor.RebuildAddressSpace(correlation, deploymentId, appliedBlob, CatalogAttempt: _catalogAttempt,
|
||||
ArtifactRevision: ArtifactRevisionOf(appliedBlob)));
|
||||
if (appliedBlob is not null) StampStubbedDriverValueNodes();
|
||||
_log.Info("DriverHost {Node}: restored served state for applied deployment {Id} on bootstrap", _localNode, deploymentId);
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -5418,6 +5422,53 @@ public sealed partial class DriverHostActor : ReceiveActor, IWithTimers, IWithUn
|
||||
_localNode, driverInstanceId, writes.Count);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gitea #1113 item 4 — stamps <see cref="OpcUaStatus.BadConfigurationError"/> on every raw NodeId and every
|
||||
/// referencing UNS NodeId of each STUBBED child (or only <paramref name="onlyDriverInstanceId"/>): a stub (no
|
||||
/// factory for the type, a factory that rejected the config, or a type not allowed on this node's roles) never
|
||||
/// publishes, so its nodes would otherwise sit at <see cref="OpcUaStatus.BadWaitingForInitialData"/> forever —
|
||||
/// a promise of a first value that cannot come.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <para>
|
||||
/// Called after each apply's <see cref="OpcUa.OpcUaPublishActor.RebuildAddressSpace"/> Tell (deploy, boot from
|
||||
/// cache, bootstrap restore) on the same host→publish-actor pair, so the publish actor has already started
|
||||
/// that plan: the write lands on the nodes that exist now AND is deferred and replayed onto the nodes the apply
|
||||
/// creates or recreates (a fresh deploy, a rebuild) — re-sent every apply because a rebuild resets them. And
|
||||
/// after an operator Restart that respawned a stub. A config-change respawn into a stub gets the respawn's
|
||||
/// <c>BadWaitingForInitialData</c> first (at the stop), then this.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// Status-only and not a comms loss: nothing is latched. A latch the previous incarnation left (a respawn
|
||||
/// of a comms-lost driver, #1113 item 2) is dropped — a stub never connects, so its audit could never arm.
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
/// <param name="onlyDriverInstanceId">Restrict to this driver; <see langword="null"/> for every stubbed child.</param>
|
||||
private void StampStubbedDriverValueNodes(string? onlyDriverInstanceId = null)
|
||||
{
|
||||
if (_opcUaPublishActor is null) return;
|
||||
List<StatusWrite>? writes = null;
|
||||
DateTime ts = default;
|
||||
foreach (var (driverId, child) in _children)
|
||||
{
|
||||
if (!child.Stubbed) continue;
|
||||
if (onlyDriverInstanceId is not null && !string.Equals(driverId, onlyDriverInstanceId, StringComparison.Ordinal)) continue;
|
||||
ForgetCommsLatch(driverId);
|
||||
if (!_valueRefsByDriver.TryGetValue(driverId, out var entries) || entries.Count == 0) continue;
|
||||
if (writes is null) { writes = new List<StatusWrite>(); ts = DateTime.UtcNow; }
|
||||
var before = writes.Count;
|
||||
foreach (var (_, nodes) in entries)
|
||||
foreach (var n in nodes)
|
||||
writes.Add(new StatusWrite(n.NodeId, OpcUaStatus.BadConfigurationError, ts, n.Realm));
|
||||
_log.Info(
|
||||
"DriverHost {Node}: driver {Driver} ({Type}) is a stub on this node — {Count} value node(s) marked BadConfigurationError",
|
||||
_localNode, driverId, child.DriverType, writes.Count - before);
|
||||
}
|
||||
|
||||
if (writes is { Count: > 0 })
|
||||
_opcUaPublishActor.Tell(new OpcUa.OpcUaPublishActor.AttributeStatusBatchUpdate(writes));
|
||||
}
|
||||
|
||||
/// <summary>Marks a child this host is about to stop as retired and watches it until it terminates.</summary>
|
||||
/// <param name="child">The child being stopped.</param>
|
||||
private void RetireChild(IActorRef child)
|
||||
@@ -5534,6 +5585,8 @@ public sealed partial class DriverHostActor : ReceiveActor, IWithTimers, IWithUn
|
||||
|
||||
// Respawn from the same spec the last reconcile used — preserves RowId, Name, ClusterId.
|
||||
SpawnChild(entry.Spec);
|
||||
// #1113 item 4: a stub replacement will never publish — not "waiting for initial data".
|
||||
StampStubbedDriverValueNodes(msg.DriverInstanceId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
+54
-3
@@ -224,6 +224,56 @@ public sealed class DriverHostRespawnValueNodeGapTests : RuntimeActorTestBase
|
||||
TestContext.Current.CancellationToken);
|
||||
}
|
||||
|
||||
// ---- #1113 item 4: a stubbed replacement / a stub deploy ----
|
||||
|
||||
/// <summary>
|
||||
/// #1113 item 4: when the replacement is a STUB (here: no factory for the type), its nodes would otherwise sit at
|
||||
/// <c>BadWaitingForInitialData</c> forever. They go <c>BadConfigurationError</c>, after the respawn stamp — for a
|
||||
/// config change after the apply's <c>RebuildAddressSpace</c> (so the publish actor replays it onto the nodes the
|
||||
/// apply recreates), including the ref the new deployment adds.
|
||||
/// </summary>
|
||||
[Theory]
|
||||
[InlineData(false)]
|
||||
[InlineData(true)]
|
||||
public void A_stubbed_replacement_marks_the_value_nodes_BadConfigurationError(bool configChange)
|
||||
{
|
||||
var oldDriver = new GatedDriver(DriverId);
|
||||
var (host, publish, coordinator, db) = Arrange(oldDriver, newDriver: null);
|
||||
SeedGoodFromOldDriver(oldDriver, publish);
|
||||
|
||||
Replace(configChange, host, coordinator, db);
|
||||
|
||||
var stamp = ExpectStampBeforeAnyValue(publish);
|
||||
stamp.Items.ShouldAllBe(i => i.StatusCode == OpcUaStatus.BadWaitingForInitialData);
|
||||
var rebuildSeen = false;
|
||||
var config = (OpcUaPublishActor.AttributeStatusBatchUpdate)publish.FishForMessage(m =>
|
||||
{
|
||||
if (m is OpcUaPublishActor.RebuildAddressSpace) rebuildSeen = true;
|
||||
return m is OpcUaPublishActor.AttributeStatusBatchUpdate s
|
||||
&& s.Items.Any(i => i.StatusCode == OpcUaStatus.BadConfigurationError);
|
||||
}, PresenceBudget, cancellationToken: TestContext.Current.CancellationToken);
|
||||
var expected = configChange ? AllOldNodes.Append(TempRef).ToArray() : AllOldNodes;
|
||||
config.Items.Select(i => i.NodeId).ShouldBe(expected, ignoreOrder: true);
|
||||
config.Items.ShouldAllBe(i => i.StatusCode == OpcUaStatus.BadConfigurationError);
|
||||
rebuildSeen.ShouldBe(configChange, "a config change stamps after its apply's rebuild; a Restart has none");
|
||||
}
|
||||
|
||||
/// <summary>#1113 item 4 on a fresh deploy: a driver that is a stub from the start never gets a first value either —
|
||||
/// its nodes are marked <c>BadConfigurationError</c> right after the apply's <c>RebuildAddressSpace</c>.</summary>
|
||||
[Fact]
|
||||
public void A_fresh_deploy_of_a_stub_marks_its_value_nodes_BadConfigurationError()
|
||||
{
|
||||
var db = NewInMemoryDbFactory();
|
||||
var deploymentId = SeedTwoTagDeployment(db);
|
||||
var (_, publish, _, _) = SpawnHostAndApplyWithCoordinator(this, db, TestNode, deploymentId, RevA,
|
||||
driverFactory: new SequenceDriverFactory(new IDriver?[] { null }));
|
||||
// SpawnHostAndApplyWithCoordinator consumed the RebuildAddressSpace: the stamp is what follows it.
|
||||
var config = publish.FishForMessage<OpcUaPublishActor.AttributeStatusBatchUpdate>(_ => true, PresenceBudget,
|
||||
cancellationToken: TestContext.Current.CancellationToken);
|
||||
config.Items.Select(i => i.NodeId).ShouldBe(AllOldNodes, ignoreOrder: true);
|
||||
config.Items.ShouldAllBe(i => i.StatusCode == OpcUaStatus.BadConfigurationError);
|
||||
}
|
||||
|
||||
/// <summary>Takes the old driver comms-lost (Force Reconnect with its re-initialise held forever) and waits for the
|
||||
/// host's latched <c>BadNoCommunication</c> stamp.</summary>
|
||||
private static void GoCommsLost(GatedDriver oldDriver, IActorRef host, TestProbe publish)
|
||||
@@ -270,7 +320,7 @@ public sealed class DriverHostRespawnValueNodeGapTests : RuntimeActorTestBase
|
||||
enabled: true);
|
||||
|
||||
private (IActorRef Host, TestProbe Publish, TestProbe Coordinator, Microsoft.EntityFrameworkCore.IDbContextFactory<ZB.MOM.WW.OtOpcUa.Configuration.OtOpcUaConfigDbContext> Db)
|
||||
Arrange(GatedDriver oldDriver, GatedDriver newDriver, TimeSpan? auditDelay = null)
|
||||
Arrange(GatedDriver oldDriver, GatedDriver? newDriver, TimeSpan? auditDelay = null)
|
||||
{
|
||||
var db = NewInMemoryDbFactory();
|
||||
var deploymentId = SeedTwoTagDeployment(db);
|
||||
@@ -352,8 +402,9 @@ public sealed class DriverHostRespawnValueNodeGapTests : RuntimeActorTestBase
|
||||
return (statuses, (OpcUaPublishActor.AttributeValueBatchUpdate)msg);
|
||||
}
|
||||
|
||||
/// <summary>Hands out the given drivers in order, one per spawn (the last one repeats).</summary>
|
||||
private sealed class SequenceDriverFactory(params IDriver[] drivers) : IDriverFactory
|
||||
/// <summary>Hands out the given drivers in order, one per spawn (the last one repeats); a null is "no factory for
|
||||
/// this type", which makes the host spawn a stub.</summary>
|
||||
private sealed class SequenceDriverFactory(params IDriver?[] drivers) : IDriverFactory
|
||||
{
|
||||
private int _next;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user