fix(grpc-data): H3 review round 3 S5 — a cancel by redeploy/shutdown is not a timeout

GrpcDataConnection.ServeAsync mapped RpcException(Cancelled) without a caller
cancel to BadTimeout even when the linked channel-retired / scope / shutdown
token fired. That case is now BadNoCommunication (resumed:
BadContinuationPointInvalid), releases held chunk tokens and stops a split
request sending further sub-batches. ProjectedHistoryAccess's outer catch no
longer reads any escaped OperationCanceledException as a timeout: only the
caller's cancel or the deadline is BadTimeout, otherwise classified as
FailCancelled does. Red on revert (client test: scope moved mid-call); the
outer-catch change has no dedicated test (nothing reachable throws past
ReadGroupAsync's own catch).
This commit is contained in:
Joseph Doherty
2026-11-24 07:11:06 -05:00
parent 9c2d6273aa
commit 30d66fdc7c
3 changed files with 39 additions and 5 deletions
@@ -181,7 +181,7 @@ public sealed partial class GrpcDataConnection : IDataHistoryService
var call = await ServeAsync(selected, endpoint, request with { Budget = request.Budget with { MaxBytes = left } }, items, chunk, start,
cancellationToken).ConfigureAwait(false);
served = call.Results;
failed = call.EndpointFailed; // answered, but the endpoint failed mid-way: send it nothing more (nit a)
failed = call.EndpointFailed; // answered, but the endpoint failed or retired mid-way: send it nothing more (nit a)
}
catch (Exception ex) when (offset > 0 && !cancellationToken.IsCancellationRequested
&& ex is InvalidOperationException or ArgumentException or RpcException or HttpRequestException)
@@ -230,7 +230,7 @@ public sealed partial class GrpcDataConnection : IDataHistoryService
/// <summary>
/// Reads on one selected endpoint and assembles its chunks. Results null = the endpoint failed before answering (a fresh
/// read may move); <c>EndpointFailed</c> = it answered (per node) but failed on the way, so a caller splitting a
/// read may move); <c>EndpointFailed</c> = it answered (per node) but failed or retired on the way, so a caller splitting a
/// request sends it nothing more. Anything that escapes first releases every origin token this assembly holds — finished
/// nodes' continuations, chunk tokens, and the tokens of a response it rejected (H3 review round 3 S6).
/// </summary>
@@ -282,6 +282,16 @@ public sealed partial class GrpcDataConnection : IDataHistoryService
foreach (var k in map) final[k] ??= new(batch[k].CorrelationId, BadHistoryOperationUnsupported, [], null);
break;
}
catch (Exception ex) when (!cancellationToken.IsCancellationRequested && Retiring(selected)
&& ex is OperationCanceledException or RpcException { StatusCode: StatusCode.Cancelled })
{
// Not the caller and not a deadline: the channel retired, the scope moved or the connection is shutting down
// (a redeploy). Not a timeout and not an endpoint fault (round 3 S5): the read cannot continue here.
if (!first) ReleaseChunkTokens(selected, current);
foreach (var k in map) final[k] ??= new(batch[k].CorrelationId, batch[k].Continuation is not null ? BadContinuationPointInvalid : BadNoCommunication, [], null);
endpointFailed = true;
break;
}
catch (RpcException ex) when (ex.StatusCode is StatusCode.DeadlineExceeded or StatusCode.Cancelled && !cancellationToken.IsCancellationRequested)
{
// The call's own deadline, or the origin cancelling it at ITS unary timeout (the effective ceiling is
@@ -367,6 +377,9 @@ public sealed partial class GrpcDataConnection : IDataHistoryService
}
}
/// <summary>The call was cancelled by the connection itself: its channel retired, its scope moved, or it is shutting down.</summary>
private bool Retiring(Selected selected) =>
selected.Channel.Retired.IsCancellationRequested || _scope.CancellationToken.IsCancellationRequested || _shutdown.IsCancellationRequested;
/// <summary>Releases continuations on their issuing endpoints (<see cref="IDataHistoryService.ReleaseAsync"/>); best effort.</summary>
public async Task ReleaseHistoryAsync(IReadOnlyList<byte[]> continuations, CancellationToken cancellationToken)