fix(server): single-clock poll loop + drop dead sync GetReadyWorkerClient (Task 8 review)

This commit is contained in:
Joseph Doherty
2026-06-16 17:04:18 -04:00
parent 70d2842c16
commit 4ab3bd55e5
@@ -1672,34 +1672,7 @@ public sealed class GatewaySession
}
/// <summary>
/// Returns the worker client iff both the gateway-side session state AND
/// the worker client's own state are <see cref="SessionState.Ready"/> /
/// <see cref="WorkerClientState.Ready"/>. The two states can diverge under
/// load: <c>_state</c> only transitions on gateway-driven events (open,
/// close, fault), while <see cref="WorkerClient.State"/> can shift on
/// worker-side signals (heartbeat watchdog, pipe disconnect) before the
/// gateway's session-level reaction observes them. When that happens the
/// in-flight RPC fails fast here with both states surfaced in the
/// diagnostic (Server-030) so the actual mismatch is actionable instead
/// of misleading. The session usually transitions to <c>Faulted</c>
/// shortly after.
/// </summary>
private IWorkerClient GetReadyWorkerClient()
{
lock (_syncRoot)
{
IWorkerClient? ready = EvaluateReadyUnderLock(out string? failureMessage);
if (ready is not null)
{
return ready;
}
throw new SessionManagerException(SessionManagerErrorCode.SessionNotReady, failureMessage!);
}
}
/// <summary>
/// Bounded, opt-in async variant of <see cref="GetReadyWorkerClient"/>. When the
/// Bounded, opt-in async variant of the fail-fast readiness check. When the
/// session is <see cref="SessionState.Ready"/> but the worker has transiently diverged
/// to a non-terminal state (<see cref="WorkerClientState.Handshaking"/>/
/// <see cref="WorkerClientState.Created"/>) and the configured worker-ready wait timeout
@@ -1742,7 +1715,11 @@ public sealed class GatewaySession
DateTimeOffset deadline = _eventStreaming.TimeProvider.GetUtcNow() + _workerReadyWaitTimeout;
while (true)
{
await Task.Delay(pollIntervalMs, cancellationToken).ConfigureAwait(false);
await Task.Delay(
TimeSpan.FromMilliseconds(pollIntervalMs),
_eventStreaming.TimeProvider,
cancellationToken)
.ConfigureAwait(false);
lock (_syncRoot)
{