Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Edge Case] Actor Context might not be available inside ReceiveAsync #7122

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from

Conversation

Arkatufus
Copy link
Contributor

@Arkatufus Arkatufus commented Mar 13, 2024

This is an edge case reproduction where Context.Self (and by proxy, Context.Sender) can not be accessed inside ReceiveAsync() if async context were somehow lost.

This unit test is meant to emulate what happens if a callback function/action that accesses the actor IActorContext were being called inside a pre-compiled third party library and it uses even a single call to await SomeFunction().ConfigureAwait(false); before the callback were invoked.

This is the output of the unit test:

Xunit.Sdk.XunitException
10 Exception(s) was thrown while actors were processing messages.
    actor: worker_5, exception: There is no active ActorContext, this is most likely due to use of async operations from within this actor.
    actor: worker_3, exception: There is no active ActorContext, this is most likely due to use of async operations from within this actor.
    actor: worker_2, exception: There is no active ActorContext, this is most likely due to use of async operations from within this actor.
    actor: worker_8, exception: There is no active ActorContext, this is most likely due to use of async operations from within this actor.
    actor: worker_6, exception: There is no active ActorContext, this is most likely due to use of async operations from within this actor.
    actor: worker_7, exception: There is no active ActorContext, this is most likely due to use of async operations from within this actor.
    actor: worker_4, exception: There is no active ActorContext, this is most likely due to use of async operations from within this actor.
    actor: worker_0, exception: There is no active ActorContext, this is most likely due to use of async operations from within this actor.
    actor: worker_1, exception: There is no active ActorContext, this is most likely due to use of async operations from within this actor.
    actor: worker_9, exception: There is no active ActorContext, this is most likely due to use of async operations from within this actor.
   at Akka.Tests.Dispatch.ActorAsyncAwaitSpec.ReceiveActorSelfInsideAsyncCallback() in D:\git\akkadotnet\akka.net\src\core\Akka.Tests\Dispatch\AsyncAwaitSpec.cs:line 405
   at Xunit.Sdk.TestInvoker`1.<>c__DisplayClass48_0.<<InvokeTestMethodAsync>b__1>d.MoveNext() in /_/src/xunit.execution/Sdk/Frameworks/Runners/TestInvoker.cs:line 276
--- End of stack trace from previous location ---
   at Xunit.Sdk.ExecutionTimer.AggregateAsync(Func`1 asyncAction) in /_/src/xunit.execution/Sdk/Frameworks/ExecutionTimer.cs:line 48
   at Xunit.Sdk.ExceptionAggregator.RunAsync(Func`1 code) in /_/src/xunit.core/Sdk/ExceptionAggregator.cs:line 90


Received 10 messages within 10.0447699 seconds. Expected message counts: 20

Copy link
Contributor Author

@Arkatufus Arkatufus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Self review

Comment on lines +329 to +330
// ConfigureAwait(false) breaks async context flow, making Self inaccessible inside Action
.ConfigureAwait(false);
Copy link
Contributor Author

@Arkatufus Arkatufus Mar 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that this unit test will run just fine if we remove .ConfigureAwait(false), but of course users would likely be stuck with code that uses .ConfigureAwait(false) if they were using a third party package.

@Arkatufus
Copy link
Contributor Author

Note that this problem can be prevented if we close Self inside the message handler.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug-reproduction Used to reproduce bugs. discussion NO MERGE Don't merge.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant