Fix reliability findings
This commit is contained in:
@@ -66,6 +66,8 @@ public sealed class EventStreamService(
|
||||
{
|
||||
await streamCts.CancelAsync().ConfigureAwait(false);
|
||||
subscriber.Dispose();
|
||||
Interlocked.Exchange(ref streamQueueDepth, 0);
|
||||
metrics.SetGrpcEventStreamQueueDepth(0);
|
||||
metrics.StreamDisconnected("Detached");
|
||||
|
||||
try
|
||||
|
||||
@@ -101,6 +101,17 @@ public sealed class GatewayMetrics : IDisposable
|
||||
_sessionsClosedCounter.Add(1);
|
||||
}
|
||||
|
||||
public void SessionRemoved()
|
||||
{
|
||||
lock (_syncRoot)
|
||||
{
|
||||
if (_openSessions > 0)
|
||||
{
|
||||
_openSessions--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void WorkerStarted(TimeSpan startupDuration)
|
||||
{
|
||||
lock (_syncRoot)
|
||||
|
||||
@@ -184,8 +184,11 @@ public sealed class SessionManager : ISessionManager
|
||||
exception,
|
||||
"Graceful shutdown failed for session {SessionId}; killing worker.",
|
||||
session.SessionId);
|
||||
session.KillWorker(GatewayShutdownReason);
|
||||
await RemoveSessionAsync(session).ConfigureAwait(false);
|
||||
if (_registry.TryGet(session.SessionId, out _))
|
||||
{
|
||||
session.KillWorker(GatewayShutdownReason);
|
||||
await RemoveSessionAsync(session).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -210,7 +213,13 @@ public sealed class SessionManager : ISessionManager
|
||||
catch (Exception exception)
|
||||
{
|
||||
session.MarkFaulted(exception.Message);
|
||||
if (!wasClosed)
|
||||
{
|
||||
_metrics.SessionRemoved();
|
||||
}
|
||||
|
||||
_metrics.Fault(SessionManagerErrorCode.CloseFailed.ToString());
|
||||
await RemoveSessionAsync(session).ConfigureAwait(false);
|
||||
throw new SessionManagerException(
|
||||
SessionManagerErrorCode.CloseFailed,
|
||||
$"Failed to close session {session.SessionId}.",
|
||||
|
||||
Reference in New Issue
Block a user