fix(grpc): configure Kestrel HTTP/2 keepalive (60 s ping, 10 s timeout) under MxGateway:Protocol (SES-005, #253)

This commit is contained in:
Joseph Doherty
2026-12-03 10:03:53 -05:00
parent 87b8f8da09
commit a474d3219b
8 changed files with 259 additions and 4 deletions
@@ -714,6 +714,19 @@ public sealed class GatewayOptionsValidator : OptionsValidatorBase<GatewayOption
builder.Add(
$"MxGateway:Protocol:MaxGrpcMessageBytes must be between {MinimumMaxMessageBytes} and {MaximumMaxMessageBytes}.");
}
// Kestrel rejects a non-positive ping delay or timeout, so 0 is the explicit "off" for the
// delay only; the timeout must always be a real bound.
if (options.Http2KeepAlivePingDelaySeconds is < 0 or > 86400)
{
builder.Add(
"MxGateway:Protocol:Http2KeepAlivePingDelaySeconds must be between 0 (disabled) and 86400.");
}
if (options.Http2KeepAlivePingTimeoutSeconds is < 1 or > 3600)
{
builder.Add("MxGateway:Protocol:Http2KeepAlivePingTimeoutSeconds must be between 1 and 3600.");
}
}
// The worker-frame (pipe) maximum must stay above the public gRPC cap by the envelope-overhead
@@ -3,7 +3,7 @@ using ZB.MOM.WW.MxGateway.Contracts;
namespace ZB.MOM.WW.MxGateway.Server.Configuration;
/// <summary>
/// Configuration options for the worker protocol version.
/// Configuration options for the worker protocol version and the public gRPC (HTTP/2) transport.
/// </summary>
public sealed class ProtocolOptions
{
@@ -14,4 +14,21 @@ public sealed class ProtocolOptions
/// <summary>Gets or sets the maximum gRPC message size in bytes.</summary>
public int MaxGrpcMessageBytes { get; init; } = 16 * 1024 * 1024;
/// <summary>
/// Gets or sets how long an HTTP/2 connection may be idle (no frames received) before the
/// gateway sends a keepalive PING, in seconds. <c>0</c> disables server pings. Maps to
/// Kestrel's <c>Limits.Http2.KeepAlivePingDelay</c>. Without it a client that vanished
/// without a FIN or RST (power loss, a firewall or NAT idle drop) holds its
/// <c>StreamEvents</c> call, its session and its worker until a write times out, which on a
/// quiet session may be never.
/// </summary>
public int Http2KeepAlivePingDelaySeconds { get; init; } = 60;
/// <summary>
/// Gets or sets how long the gateway waits for any frame after sending a keepalive PING
/// before it closes the connection, in seconds. Maps to Kestrel's
/// <c>Limits.Http2.KeepAlivePingTimeout</c>.
/// </summary>
public int Http2KeepAlivePingTimeoutSeconds { get; init; } = 10;
}