fix(grpc-data): H3 review round 3 nits b/c/d — no origin cursor stranded on Bad, scope moves or a serve-time throw
- b: ProjectedHistoryAccess releases the prior origin cursor on any Bad answer to a resumed node (and on a mismatched answer) — an unsent refusal left it open at the origin; idempotent. - c: DataConnectionDeploymentLease, when its scope moves while a history answer is in flight, releases the dropped answer's new continuations (best effort); resumed items are BadContinuationPointInvalid, fresh ones BadNoCommunication. - d: ProjectedHistoryRead: a throw while serving outcome i (FromClr on an unconvertible value, a store fault) releases outcome i's cursor unless the store already owns it, and every later outcome's. Each red on revert (mutation).
This commit is contained in:
+14
-2
@@ -541,13 +541,25 @@ public sealed class DataConnectionDeploymentLease : IDataConnection, IDataHistor
|
||||
catch (Exception ex) when (ex is InvalidOperationException or UnauthorizedAccessException or OperationCanceledException
|
||||
&& !cancellationToken.IsCancellationRequested)
|
||||
{
|
||||
// The scope moved while the answer was in flight: the answer is dropped, so the new origin continuations it carries are
|
||||
// released (best effort) rather than stranded until the origin's idle expiry (H3 review round 3 nit c).
|
||||
var orphans = value.Select(x => x.Continuation).OfType<byte[]>().ToArray();
|
||||
foreach (var item in value) item.Dispose();
|
||||
return Unavailable(request); // the scope moved while the answer was in flight
|
||||
if (orphans.Length > 0) _ = ReleaseQuietlyAsync(history, orphans);
|
||||
return Unavailable(request);
|
||||
}
|
||||
}
|
||||
|
||||
private static async Task ReleaseQuietlyAsync(IDataHistoryService history, byte[][] continuations)
|
||||
{
|
||||
try { await history.ReleaseAsync(continuations, CancellationToken.None).ConfigureAwait(false); }
|
||||
catch (Exception ex) when (ex is not OutOfMemoryException) { } // best effort; the origin's idle expiry is the backstop
|
||||
}
|
||||
|
||||
/// <summary>A resumed item's token cannot be presented again: <c>BadContinuationPointInvalid</c>; a fresh one <c>BadNoCommunication</c>.</summary>
|
||||
private static DataHistoryReadResult[] Unavailable(DataHistoryReadRequest request) => request.Items
|
||||
.Select(x => new DataHistoryReadResult(x.CorrelationId, GrpcDataConnection.BadNoCommunication, [], null)).ToArray();
|
||||
.Select(x => new DataHistoryReadResult(x.CorrelationId,
|
||||
x.Continuation is not null ? GrpcDataConnection.BadContinuationPointInvalid : GrpcDataConnection.BadNoCommunication, [], null)).ToArray();
|
||||
|
||||
Task<IReadOnlyList<DataHistoryReadResult>> IDataHistoryService.ReadAsync(DataHistoryReadRequest request, CancellationToken cancellationToken) =>
|
||||
ReadHistoryAsync(request, cancellationToken);
|
||||
|
||||
Reference in New Issue
Block a user