fix(workers): fail fast when the worker exits before connecting; launch-cleanup Kill never masks the launch error (WRK-002, WRK-006, #253)

This commit is contained in:
Joseph Doherty
2026-12-03 09:56:05 -05:00
parent 2c22ae6bd4
commit 196465ef9c
6 changed files with 236 additions and 22 deletions
@@ -293,6 +293,10 @@ public sealed class WorkerProcessLauncher : IWorkerProcessLauncher
return workingDirectory;
}
// Called from the launch-failure catch blocks, so it must never throw: Kill can raise
// Win32Exception (the process is mid-termination, or access is denied) or AggregateException
// (a descendant could not be terminated), and an exception escaping here would replace the
// WorkerProcessLaunchException the caller is owed (WRK-006).
private void KillAndDispose(IWorkerProcess process, string reason)
{
try
@@ -303,12 +307,32 @@ public sealed class WorkerProcessLauncher : IWorkerProcessLauncher
_metrics.WorkerKilled(reason);
}
}
catch (Exception exception)
{
_logger.LogWarning(
exception,
"Killing worker process {ProcessId} after a failed launch ({Reason}) failed.",
SafeProcessId(process),
reason);
}
finally
{
process.Dispose();
}
}
private static int? SafeProcessId(IWorkerProcess process)
{
try
{
return process.Id;
}
catch (InvalidOperationException)
{
return null;
}
}
private static void ValidateRequest(WorkerProcessLaunchRequest request)
{
if (string.IsNullOrWhiteSpace(request.SessionId))