fix(mtconnect): an Agent refusal of /current is a reply, not a comms fault
Health contract: an MTConnectError document (NO_DEVICE, INVALID_REQUEST, ...) is the Agent answering. The parsers now mark such an InvalidDataException (MTConnectXml.IsAgentRefusal - the type is sealed, so a Data marker, every other handler unchanged); ReadAsync reports the batch Bad but does not degrade the read path, advances LastSuccessfulRead, clears a prior read degradation and warns once per distinct refusal. An unparseable answer stays a comms fault. Refs #743 Claude-Session: https://claude.ai/code/session_01Ub9hGmYLQvn9XETzw7CMsT
This commit is contained in:
@@ -369,6 +369,9 @@ public sealed partial class MTConnectDriver
|
||||
/// <summary>Whether the <c>/current</c> read path is currently failing. See <see cref="PublishHealthy"/>.</summary>
|
||||
private volatile bool _readDegraded;
|
||||
|
||||
/// <summary>The last <c>/current</c> refusal text logged, so a persistent refusal warns once, not per read.</summary>
|
||||
private string? _lastReadRefusal;
|
||||
|
||||
/// <summary>
|
||||
/// Whether the current-generation <c>/sample</c> pump has delivered since it started (a chunk, a heartbeat or
|
||||
/// a re-baseline) — the precondition, with <see cref="_streamDegraded"/> clear, for <see cref="ReadAsync"/>
|
||||
@@ -770,6 +773,23 @@ public sealed partial class MTConnectDriver
|
||||
// handled below as the Agent failure it is.
|
||||
throw;
|
||||
}
|
||||
catch (InvalidDataException ex) when (MTConnectXml.IsAgentRefusal(ex))
|
||||
{
|
||||
// The health contract: an MTConnectError document is the Agent REFUSING the request (a bad device
|
||||
// scope, an unsupported request) — it answered. The batch is Bad, but this is not a comms fault: the
|
||||
// read path is not degraded by it (that would reconnect-loop a driver over a config problem), the stamp
|
||||
// advances, and the Agent's text is logged once per distinct refusal.
|
||||
_readDegraded = false;
|
||||
PublishHealthy(DateTime.UtcNow);
|
||||
if (!string.Equals(Interlocked.Exchange(ref _lastReadRefusal, ex.Message), ex.Message, StringComparison.Ordinal))
|
||||
{
|
||||
_logger.LogWarning(
|
||||
"MTConnect driver {DriverInstanceId}: {AgentUri} refused /current — {AgentError}. Every read is reported Bad until the Agent accepts the request; the driver stays connected.",
|
||||
_driverInstanceId, AgentDisplay(options), ex.Message);
|
||||
}
|
||||
|
||||
return BadBatch(fullReferences.Count, BadCommunicationError);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
DegradeAfterReadFailure(ex);
|
||||
|
||||
Reference in New Issue
Block a user