diff --git a/src/Drivers/ZB.MOM.WW.OtOpcUa.Driver.Historian.Gateway/GatewayAlarmHistorianWriter.cs b/src/Drivers/ZB.MOM.WW.OtOpcUa.Driver.Historian.Gateway/GatewayAlarmHistorianWriter.cs
index 886faa9cb..32600475f 100644
--- a/src/Drivers/ZB.MOM.WW.OtOpcUa.Driver.Historian.Gateway/GatewayAlarmHistorianWriter.cs
+++ b/src/Drivers/ZB.MOM.WW.OtOpcUa.Driver.Historian.Gateway/GatewayAlarmHistorianWriter.cs
@@ -101,16 +101,21 @@ public sealed class GatewayAlarmHistorianWriter : IAlarmHistorianWriter, IDispos
///
internal static bool IsGatewayAnswer(Exception exception)
{
+ // One authority: IsSystemicFailure owns the whole classification, including a client-fabricated status (#1103).
if (IsSystemicFailure(exception)) return false;
- for (Exception? e = exception; e is not null; e = e.InnerException)
- {
- if (e is not RpcException rpc) continue;
- if (rpc.Status.DebugException is not null) return false;
- var detail = rpc.Status.Detail ?? string.Empty;
- foreach (var prefix in TransportDetailPrefixes)
- if (detail.StartsWith(prefix, StringComparison.Ordinal)) return false;
- return true;
- }
+ return StatusOf(exception) is not null;
+ }
+
+ ///
+ /// True when the status was fabricated client-side (Grpc.Net.Client transport exception attached as
+ /// DebugException, or a client/proxy detail prefix) rather than sent by the gateway (#1096/#1103).
+ ///
+ private static bool IsClientFabricated(RpcException rpc)
+ {
+ if (rpc.Status.DebugException is not null) return true;
+ var detail = rpc.Status.Detail ?? string.Empty;
+ foreach (var prefix in TransportDetailPrefixes)
+ if (detail.StartsWith(prefix, StringComparison.Ordinal)) return true;
return false;
}
@@ -314,27 +319,34 @@ public sealed class GatewayAlarmHistorianWriter : IAlarmHistorianWriter, IDispos
}
/// The gRPC status of a gateway failure (raw, or wrapped by the package client); null when it has none.
- private static StatusCode? StatusOf(Exception exception)
+ private static StatusCode? StatusOf(Exception exception) => FirstRpc(exception)?.StatusCode;
+
+ private static RpcException? FirstRpc(Exception exception)
{
for (Exception? e = exception; e is not null; e = e.InnerException)
- if (e is RpcException rpc) return rpc.StatusCode;
+ if (e is RpcException rpc) return rpc;
return null;
}
///
/// Whether a RetryPlease-class failure is a KNOWN outage of the whole gateway path (so re-sending event by event would
/// only multiply the round trips): the transient / back-pressure / auth / deadline / server-cancellation codes, and a
- /// status-less failure whose chain holds a transport fault (socket, I/O, HTTP, a disposed channel, a timeout or an
+ /// client-fabricated status (#1103), and a status-less failure whose chain holds a transport fault (socket, I/O, HTTP, a disposed channel, a timeout or an
/// internal cancellation). Everything else — Unknown, Internal, DataLoss, unlisted codes, a
/// client exception with no status and no transport cause, any other exception — is unrecognised and gets the chunk
/// isolated per event.
///
internal static bool IsSystemicFailure(Exception exception)
{
- if (StatusOf(exception) is { } code)
+ if (FirstRpc(exception) is { } rpc)
+ {
+ // #1103: a proxy/transport-fabricated status of ANY code is an outage of the path, not an event-level fault.
+ if (IsClientFabricated(rpc)) return true;
+ var code = rpc.StatusCode;
return code is StatusCode.Unavailable or StatusCode.DeadlineExceeded or StatusCode.Cancelled
or StatusCode.ResourceExhausted or StatusCode.Aborted or StatusCode.Unauthenticated
or StatusCode.PermissionDenied;
+ }
for (Exception? e = exception; e is not null; e = e.InnerException)
if (e is HistorianGatewayUnavailableException or HistorianGatewayAuthenticationException
or HistorianGatewayAuthorizationException
diff --git a/tests/Drivers/ZB.MOM.WW.OtOpcUa.Driver.Historian.Gateway.Tests/GatewayAlarmWriterReachabilityTests.cs b/tests/Drivers/ZB.MOM.WW.OtOpcUa.Driver.Historian.Gateway.Tests/GatewayAlarmWriterReachabilityTests.cs
index 9fcaf4d57..589d0a939 100644
--- a/tests/Drivers/ZB.MOM.WW.OtOpcUa.Driver.Historian.Gateway.Tests/GatewayAlarmWriterReachabilityTests.cs
+++ b/tests/Drivers/ZB.MOM.WW.OtOpcUa.Driver.Historian.Gateway.Tests/GatewayAlarmWriterReachabilityTests.cs
@@ -77,6 +77,26 @@ public sealed class GatewayAlarmWriterReachabilityTests
GatewayAlarmHistorianWriter.IsGatewayAnswer(new HistorianGatewayException("x")).ShouldBeFalse();
}
+ // #1103: IsSystemicFailure shares the same classification.
+ [Theory]
+ [InlineData(StatusCode.Internal)]
+ [InlineData(StatusCode.Unknown)]
+ public void A_genuine_gateway_Internal_or_Unknown_is_not_systemic(StatusCode code) =>
+ GatewayAlarmHistorianWriter.IsSystemicFailure(Wrapped(code)).ShouldBeFalse();
+
+ [Theory]
+ [InlineData(StatusCode.Internal, "Bad gRPC response. HTTP status code: 500")]
+ [InlineData(StatusCode.Unknown, "Error reading next message. IOException: reset")]
+ public void A_fabricated_Internal_or_Unknown_is_systemic(StatusCode code, string detail) =>
+ GatewayAlarmHistorianWriter.IsSystemicFailure(WrappedRpc(code, detail)).ShouldBeTrue();
+
+ [Theory]
+ [InlineData(StatusCode.Internal)]
+ [InlineData(StatusCode.Unknown)]
+ public void A_status_with_a_transport_debug_exception_is_systemic(StatusCode code) =>
+ GatewayAlarmHistorianWriter.IsSystemicFailure(
+ WrappedRpc(code, "Received RST_STREAM with error code 2", new IOException("reset"))).ShouldBeTrue();
+
[Theory]
[InlineData(StatusCode.Internal)]
[InlineData(StatusCode.Unknown)]