fix(historian): append and alarm loops capture their lifetime token up front (lmxopcua#746)
Both off-mailbox loops read _lifetime.Token per operation. PostStop disposes that source after the flush budget, and a disposed source's Token throws, so an operation started past the budget would have logged a spurious failure. Each loop now captures the token when it starts. Also rewrites the recorder's stale "capture Self before the await" note for the enqueue path. Rebased from the unpushed remed/lane-H2 branch (originally authored 2026-10-22 in session_01Ub9hGmYLQvn9XETzw7CMsT) onto current master. Claude-Session: https://claude.ai/code/session_01GT67AEHd2Acv1YPwGfXEoV
This commit is contained in:
@@ -182,8 +182,10 @@ public sealed class HistorianAdapterActor : ReceiveActor
|
||||
/// <summary>The single loop feeding the sink, in arrival order. Never throws: a rejected event is logged.</summary>
|
||||
private async Task DrainAsync()
|
||||
{
|
||||
// Captured now: PostStop disposes the source after the flush budget, and a disposed source's Token throws.
|
||||
var lifetime = _lifetime.Token;
|
||||
await foreach (var evt in _queue.Reader.ReadAllAsync(CancellationToken.None).ConfigureAwait(false))
|
||||
await EnqueueAsync(evt).ConfigureAwait(false);
|
||||
await EnqueueAsync(evt, lifetime).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
/// <summary>Caches this node's <see cref="RedundancyRole"/> from a cluster redundancy snapshot so the
|
||||
@@ -205,13 +207,13 @@ public sealed class HistorianAdapterActor : ReceiveActor
|
||||
}
|
||||
}
|
||||
|
||||
private async Task EnqueueAsync(AlarmHistorianEvent evt)
|
||||
private async Task EnqueueAsync(AlarmHistorianEvent evt, CancellationToken lifetime)
|
||||
{
|
||||
try
|
||||
{
|
||||
await _sink.EnqueueAsync(evt, _lifetime.Token).ConfigureAwait(false);
|
||||
await _sink.EnqueueAsync(evt, lifetime).ConfigureAwait(false);
|
||||
}
|
||||
catch (OperationCanceledException) when (_lifetime.IsCancellationRequested)
|
||||
catch (OperationCanceledException) when (lifetime.IsCancellationRequested)
|
||||
{
|
||||
// Stopped past the flush budget.
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user