fix(probe): bound OpcUaClient/AbCip handshakes by timeout CTS; IPv4 preflight; stop sw (code-review)
This commit is contained in:
@@ -59,12 +59,17 @@ public sealed class AbCipDriverProbe : IDriverProbe
|
||||
var host = parsed.Gateway;
|
||||
var port = parsed.Port;
|
||||
|
||||
// Bound both phases by the caller timeout, independent of `ct`, so a device that accepts
|
||||
// TCP but stalls the CIP Forward Open cannot hang the probe.
|
||||
using var cts = CancellationTokenSource.CreateLinkedTokenSource(ct);
|
||||
cts.CancelAfter(timeout);
|
||||
|
||||
// Phase 1: bare TCP preflight — fast rejection for unreachable hosts.
|
||||
var sw = Stopwatch.StartNew();
|
||||
try
|
||||
{
|
||||
using var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
|
||||
await socket.ConnectAsync(host, port, ct);
|
||||
await socket.ConnectAsync(host, port, cts.Token);
|
||||
}
|
||||
catch (SocketException ex)
|
||||
{
|
||||
@@ -106,7 +111,7 @@ public sealed class AbCipDriverProbe : IDriverProbe
|
||||
var rt = new LibplctagTagRuntime(p);
|
||||
try
|
||||
{
|
||||
await rt.InitializeAsync(ct);
|
||||
await rt.InitializeAsync(cts.Token);
|
||||
sw.Stop();
|
||||
|
||||
// InitializeAsync completed without throwing — either the tag was found (Ok) or
|
||||
@@ -131,7 +136,10 @@ public sealed class AbCipDriverProbe : IDriverProbe
|
||||
{
|
||||
// LibPlcTagException carries the Status; classify as reachable vs transport failure.
|
||||
if (IsReachableException(ex))
|
||||
{
|
||||
sw.Stop();
|
||||
return new(true, "CIP session OK (controller reachable; probe tag not found)", sw.Elapsed);
|
||||
}
|
||||
|
||||
return new(false, $"Reachable at {host}:{port} but CIP handshake failed: {ex.Message}", null);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user