fix(client-dotnet): keepalive, error mapping, lifecycle, CLI batch/redaction (CDN-001..011, #257)

- keepalive: 30 s ping / 10 s timeout / Always, configurable via KeepAlivePingDelay/Timeout (CDN-004, D7)
- GrpcStatusMapper shared by both transports: server Cancelled with a live token is no longer
  OperationCanceledException; NotFound/FailedPrecondition on session RPCs -> MxGatewaySessionException;
  MxGatewayException.GrpcStatusCode preserves the status (CDN-001, CDN-002)
- Register/AddItem/AddItem2 raise MxGatewayMalformedReplyException on a payload-less reply (CDN-008)
- MxGatewayEventStream.DisposeAsync waits for the in-flight read (CDN-003); session DisposeAsync
  is bounded to 5 s and swallows cancellation (CDN-005); owned handler + pinned CA disposed (CDN-006)
- ResourceExhausted no longer retried (CDN-007)
- CLI: batch reuses clients, stream/bench commands exempt from the 30 s timeout, OCE reported as
  an error with exit 1, --value redacted only for write-secured* and only as a whole token,
  bench backs off on failures (CDN-009, CDN-010, CDN-011)
This commit is contained in:
Joseph Doherty
2026-12-03 09:44:02 -05:00
parent d12fd4f5a0
commit 31e16fbc80
19 changed files with 974 additions and 180 deletions
+7 -2
View File
@@ -111,6 +111,8 @@ public sealed class MxGatewayClientOptions
public string? ServerNameOverride { get; init; }
public TimeSpan ConnectTimeout { get; init; } = TimeSpan.FromSeconds(10);
public TimeSpan DefaultCallTimeout { get; init; } = TimeSpan.FromSeconds(30);
public TimeSpan KeepAlivePingDelay { get; init; } = TimeSpan.FromSeconds(30);
public TimeSpan KeepAlivePingTimeout { get; init; } = TimeSpan.FromSeconds(10);
public MxGatewayClientRetryOptions Retry { get; init; } = new();
public ILoggerFactory? LoggerFactory { get; init; }
}
@@ -118,7 +120,7 @@ public sealed class MxGatewayClientOptions
The .NET client applies a bounded Polly retry policy only to idempotent calls:
`CloseSession` and diagnostic `Invoke` commands such as `Ping`,
`GetSessionState`, and `GetWorkerInfo`. It does not retry `OpenSession`, event
`GetSessionState`, and `GetWorkerInfo`. Only `Unavailable` and `DeadlineExceeded` are retried. It does not retry `OpenSession`, event
streams, writes, secured writes, authentication, registration, item management,
or subscription changes because those calls can partially succeed in MXAccess.
@@ -157,7 +159,10 @@ The interceptor must redact the key in logs and exceptions.
Expose `StreamEventsAsync` as `IAsyncEnumerable<MxEvent>`. On cancellation,
cancel the gRPC stream and surface `OperationCanceledException` only when the
caller initiated cancellation.
caller initiated cancellation. A server-sent `Cancelled` status becomes
`MxGatewayException`; `NotFound` / `FailedPrecondition` become
`MxGatewaySessionException`. The channel sends HTTP/2 keepalive pings every 30 s
(10 s timeout, also with no active call) so a half-open connection fails the read.
Do not reorder events.