qa iteration 1
This commit is contained in:
@@ -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
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user