fix(worker): review 2026-10-21 stream E — cache eviction, phased ReadBulk, poll/STA fault handling
ci / nightly-windev (push) Has been skipped
ci / windows-x86 (push) Failing after 1m3s
ci / java (push) Successful in 2m17s
ci / portable (push) Failing after 4m42s

- RemoveItem/Unregister evict value + write-completion caches (leak under churn)
- ReadBulk snapshot path: add/advise all, one shared deadline, then tear down
- alarm poll faults only after 3 consecutive failures; transient ones logged
- AlarmCommandHandler disposes primary when standby build throws
- StaRuntime pumps between queued work items
- WRK-02: post-start STA loop death surfaces as StaHung WorkerFault
- WRK-09: AppDomain unhandled-exception hook, exit code 7
- RETRIGGER documented as reserved, never synthesized
- TST-05: live facts for Ping/GetSessionState/GetWorkerInfo/DrainEvents/ShutdownWorker
This commit is contained in:
Joseph Doherty
2026-10-22 06:19:32 -04:00
parent 488649ce99
commit 7618cafb6c
22 changed files with 1859 additions and 90 deletions
@@ -14,10 +14,61 @@ public static class WorkerApplication
/// <returns>The process exit code.</returns>
public static int Run(string[] args)
{
WorkerConsoleLogger logger = new(Console.Error);
// WRK-09: installed only on the production entry point (not the
// injectable overloads tests call) because the hook is process-global.
AppDomain.CurrentDomain.UnhandledException += (_, eventArgs) =>
HandleUnhandledException(
logger,
eventArgs.ExceptionObject,
eventArgs.IsTerminating,
Environment.Exit);
return Run(
args,
new EnvironmentVariableWorkerEnvironment(),
new WorkerConsoleLogger(Console.Error));
logger);
}
/// <summary>
/// Body of the worker's <c>AppDomain.CurrentDomain.UnhandledException</c>
/// hook. Logs one <c>WorkerUnhandledException</c> line and exits the
/// process with <see cref="WorkerExitCode.UnhandledException"/>, so the
/// gateway's launcher sees a defined worker exit code rather than the
/// CLR's crash code.
/// </summary>
/// <remarks>
/// Logs the exception type only — never its message or stack, which
/// can carry tag values or credentials passed through a command — the
/// same rule every other worker failure line follows. A logging
/// failure is swallowed so the exit always happens.
/// </remarks>
/// <param name="logger">Worker logger.</param>
/// <param name="exceptionObject">The unhandled exception object (not necessarily an <see cref="Exception"/>).</param>
/// <param name="isTerminating">Whether the CLR is terminating the process.</param>
/// <param name="exit">Process-exit action; <see cref="Environment.Exit"/> in production.</param>
internal static void HandleUnhandledException(
IWorkerLogger logger,
object? exceptionObject,
bool isTerminating,
Action<int> exit)
{
try
{
logger.Error("WorkerUnhandledException", new Dictionary<string, object?>
{
["exit_code"] = WorkerExitCode.UnhandledException,
["exception_type"] = exceptionObject?.GetType().FullName ?? "null",
["is_terminating"] = isTerminating,
});
}
catch
{
// Never let a logging failure skip the defined exit.
}
exit((int)WorkerExitCode.UnhandledException);
}
/// <summary>Initializes and runs the worker with custom environment and logging.</summary>