fix(worker): exit 5 on gateway death, dedicated exit 8 on event-queue overflow (mxaccessgw#186)
A frame read that hits end of stream means the gateway closed its end of the pipe (usually because it died). WorkerApplication mapped every WorkerFrameProtocolException to ProtocolViolation (6); EndOfStream now exits as PipeConnectionFailed (5), alongside the IOException a broken pipe raises. Event-queue overflow exited as the generic UnexpectedFailure (1). The event drain loop now unwinds with WorkerEventQueueFaultException carrying the fault category, and QueueOverflow exits with the new WorkerExitCode.EventQueueOverflow (8). Other categories keep exit 1. The gateway does not decode worker exit codes (it only logs the number), so no gateway change is needed. WorkerBootstrap.md and MxAccessWorkerInstanceDesign.md updated. (mxaccessgw#186) Claude-Session: https://claude.ai/code/session_01GT67AEHd2Acv1YPwGfXEoV
This commit is contained in:
@@ -1998,6 +1998,47 @@ public sealed class WorkerPipeSessionTests
|
||||
await SendShutdownAndWaitAsync(pipePair, runTask, cancellation.Token);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// When the event queue records an overflow fault, the drain loop writes the fault frame and
|
||||
/// unwinds with <see cref="WorkerEventQueueFaultException"/> carrying the category, which is
|
||||
/// what lets the process boundary exit with the dedicated overflow code (mxaccessgw#186).
|
||||
/// </summary>
|
||||
/// <returns>A task that represents the asynchronous operation.</returns>
|
||||
[Fact]
|
||||
public async Task RunAsync_WhenEventQueueOverflows_WritesFaultAndThrowsTypedException()
|
||||
{
|
||||
using CancellationTokenSource cancellation = new(TimeSpan.FromSeconds(10));
|
||||
using PipePair pipePair = await PipePair.CreateAsync(cancellation.Token);
|
||||
FakeRuntimeSession runtime = new()
|
||||
{
|
||||
PendingFault = new WorkerFault
|
||||
{
|
||||
Category = WorkerFaultCategory.QueueOverflow,
|
||||
DiagnosticMessage = "MXAccess outbound event queue reached capacity 4.",
|
||||
ProtocolStatus = new ProtocolStatus
|
||||
{
|
||||
Code = ProtocolStatusCode.WorkerUnavailable,
|
||||
Message = "MXAccess outbound event queue reached capacity 4.",
|
||||
},
|
||||
},
|
||||
};
|
||||
WorkerPipeSession session = CreatePipeSession(pipePair.WorkerStream, runtime);
|
||||
Task runTask = session.RunAsync(cancellation.Token);
|
||||
await CompleteGatewayHandshakeAsync(pipePair, cancellation.Token);
|
||||
|
||||
WorkerEnvelope faultEnvelope = await ReadUntilAsync(
|
||||
pipePair.GatewayReader,
|
||||
WorkerEnvelope.BodyOneofCase.WorkerFault,
|
||||
cancellation.Token);
|
||||
Assert.Equal(WorkerFaultCategory.QueueOverflow, faultEnvelope.WorkerFault.Category);
|
||||
|
||||
Task completedTask = await Task.WhenAny(runTask, Task.Delay(TimeSpan.FromSeconds(5), cancellation.Token));
|
||||
Assert.Same(runTask, completedTask);
|
||||
WorkerEventQueueFaultException exception =
|
||||
await Assert.ThrowsAsync<WorkerEventQueueFaultException>(async () => await runTask);
|
||||
Assert.Equal(WorkerFaultCategory.QueueOverflow, exception.Category);
|
||||
}
|
||||
|
||||
private static WorkerPipeSession CreateSession(
|
||||
Stream inbound,
|
||||
Stream outbound,
|
||||
|
||||
Reference in New Issue
Block a user