fix(opcuaclient): #1039 subscribe-time refusals ride the skipped-tag report (SkippedTagLedger.Append/Withdraw); probe preflight keeps an IPv6 zone

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Joseph Doherty
2026-12-03 15:20:27 -05:00
parent d8cf9723d1
commit eff2b8e573
7 changed files with 287 additions and 6 deletions
@@ -46,7 +46,7 @@ public sealed class OpcUaClientDriver : IDriver, ITagDiscovery, IReadable, IWrit
/// type stays free of driver bookkeeping.
/// </summary>
/// <param name="map">The map just built from the live session.</param>
private void RecordSkippedTags(NamespaceMap map)
internal void RecordSkippedTags(NamespaceMap map)
{
var authored = _options.RawTags;
_skippedTags.BeginRebuild(authored.Count);
@@ -2128,6 +2128,16 @@ public sealed class OpcUaClientDriver : IDriver, ITagDiscovery, IReadable, IWrit
foreach (var pair in itemHandlers)
if (RejectedMonitoredItemStatus(pair.Item) is { } refused)
rejected.Add(new RejectedItem(RefOf(pair.Item), refused, $"the server refused the monitored item (0x{refused:X8})"));
// #1039: a ref a LATER subscribe now serves stops being reported skipped (the report is re-asserted from the
// refusals of each subscribe, so a fixed upstream node drops off it).
if (rejected.Count == 0) { foreach (var fullRef in fullReferences) _skippedTags.Withdraw(fullRef); }
else
{
var refused = rejected.Select(r => r.Ref).ToHashSet(StringComparer.Ordinal);
foreach (var fullRef in fullReferences)
if (!refused.Contains(fullRef)) _skippedTags.Withdraw(fullRef);
}
}
}
@@ -2160,6 +2170,8 @@ public sealed class OpcUaClientDriver : IDriver, ITagDiscovery, IReadable, IWrit
internal void ReportRejectedItems(ISubscriptionHandle handle, IReadOnlyList<RejectedItem> rejected)
{
var now = Clock.GetUtcNow().UtcDateTime;
// #1039: the same refusals ride the skipped-tag report (/hosts), so an operator sees them without the log.
foreach (var r in rejected) _skippedTags.Append(r.Ref, r.Why);
lock (_deliveryLock)
{
foreach (var r in rejected)
@@ -143,7 +143,7 @@ public sealed class OpcUaClientDriverProbe : IDriverProbe
DisableHiResClock = true,
};
private static (string host, int port, string endpointUrl) ExtractTarget(OpcUaClientDriverOptions opts)
internal static (string host, int port, string endpointUrl) ExtractTarget(OpcUaClientDriverOptions opts)
{
// EndpointUrls wins over the convenience EndpointUrl when both are set.
var endpointUrl = opts.EndpointUrls.FirstOrDefault()
@@ -154,7 +154,11 @@ public sealed class OpcUaClientDriverProbe : IDriverProbe
if (!Uri.TryCreate(endpointUrl, UriKind.Absolute, out var uri))
return (string.Empty, 0, string.Empty);
var host = uri.Host;
// IdnHost, not Host: Uri.Host drops an IPv6 zone index (#819), so a link-local endpoint was dialled zone-less and
// failed the preflight as "Connect failed" before any OPC UA traffic. IdnHost is what the SDK's own transport
// dials (and it carries no brackets, which Socket.ConnectAsync's host overload does not want). An RFC 6874 "%25"
// delimiter is normalised to the "%" the socket layer expects.
var host = uri.IdnHost.Replace("%25", "%", StringComparison.Ordinal);
var port = uri.IsDefaultPort ? 4840 : uri.Port;
return (host, port, endpointUrl);
}