Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/core/Akka.Remote.Tests/RemotingSpec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,20 @@ public async Task Remoting_must_support_Ask()
Assert.IsType<FutureActorRef>(msg.Item2);
}

[Fact]
public async Task Ask_does_not_deadlock()
{
// see https://github.com/akkadotnet/akka.net/issues/2546

// the configure await causes the continuation (== the second ask) to be scheduled on the HELIOS worker thread
var msg = await here.Ask<Tuple<string, IActorRef>>("ping", TimeSpan.FromSeconds(1.5)).ConfigureAwait(false);
Assert.Equal("pong", msg.Item1);

// the .Result here blocks the helios worker thread, deadlocking the whole system.
var msg2 = here.Ask<Tuple<string, IActorRef>>("ping", TimeSpan.FromSeconds(1.5)).Result;
Assert.Equal("pong", msg2.Item1);
}

[Fact]
public void Resolve_does_not_deadlock()
{
Expand Down
2 changes: 1 addition & 1 deletion src/core/Akka/Actor/ActorRef.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ protected override void TellInternal(object message, IActorRef sender)
{
if (Interlocked.Exchange(ref status, COMPLETED) == INITIATED)
{
_result.TrySetResult(message);
Task.Run(() => _result.TrySetResult(message));
}
}
}
Expand Down