qa iteration 1

This commit is contained in:
master
2026-03-06 00:23:59 +02:00
parent a918d39a61
commit 360485f556
6 changed files with 222 additions and 12 deletions

View File

@@ -31,6 +31,14 @@ public sealed class RouterConnectionManager : IRouterConnectionManager, IDisposa
private volatile InstanceHealthStatus _currentStatus = InstanceHealthStatus.Healthy;
private int _inFlightRequestCount;
private double _errorRate;
private int _heartbeatCount;
/// <summary>
/// Number of heartbeats between periodic re-registration (HELLO re-send).
/// Ensures the gateway picks up the service after a gateway restart.
/// Default: every 30 heartbeats (~5 min at 10s intervals).
/// </summary>
private const int ReRegistrationInterval = 30;
/// <inheritdoc />
public IReadOnlyList<ConnectionState> Connections => [.. _connections.Values];
@@ -306,6 +314,38 @@ public sealed class RouterConnectionManager : IRouterConnectionManager, IDisposa
{
await Task.Delay(_options.HeartbeatInterval, cancellationToken);
_heartbeatCount++;
// Periodically re-send HELLO to handle gateway restarts.
// The gateway loses all connection state on restart, and services
// only send HELLO once on initial connect. This ensures recovery.
if (_heartbeatCount % ReRegistrationInterval == 0 && _microserviceTransport is not null && _endpoints is not null)
{
try
{
var instance = new InstanceDescriptor
{
InstanceId = _options.InstanceId,
ServiceName = _options.ServiceName,
Version = _options.Version,
Region = _options.Region
};
await _microserviceTransport.ConnectAsync(
instance,
_endpoints,
_schemas,
_openApiInfo,
cancellationToken);
_logger.LogDebug("Periodic re-registration sent (heartbeat #{Count})", _heartbeatCount);
}
catch (Exception ex)
{
_logger.LogWarning(ex, "Failed to send periodic re-registration");
}
}
// Build heartbeat payload with current status and metrics
var heartbeat = new HeartbeatPayload
{