Skip to content

Commit 2aa2f01

Browse files
committed
fix(actors): fault queued requests on stop-on-error and carry the cancellation token
1 parent 97aea99 commit 2aa2f01

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

src/SquidStd.Actors/Actor.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,7 @@ public async Task<TReply> AskAsync<TRequest, TReply>(
8585
_outstanding[request] = 0;
8686

8787
using var registration = cancellationToken.Register(
88-
static state => ((IActorRequestCore)state!).Fail(new OperationCanceledException()),
89-
request
88+
() => request.Fail(new OperationCanceledException(cancellationToken))
9089
);
9190

9291
try
@@ -129,7 +128,7 @@ private async Task ProcessAsync(TMessage message)
129128
{
130129
if (message is IActorRequestCore cancelledRequest)
131130
{
132-
cancelledRequest.Fail(new OperationCanceledException());
131+
cancelledRequest.Fail(new OperationCanceledException(_shutdown.Token));
133132
}
134133
}
135134
catch (Exception ex)
@@ -152,6 +151,11 @@ private async Task ProcessAsync(TMessage message)
152151

153152
if (_options.ErrorPolicy == ActorErrorPolicy.StopOnError)
154153
{
154+
foreach (var pending in _outstanding.Keys)
155+
{
156+
pending.Fail(new InvalidOperationException("Actor stopped due to a handler failure.", ex));
157+
}
158+
155159
throw;
156160
}
157161
}

0 commit comments

Comments
 (0)