AK2000 - Error
Do not use Ask<T> or Ask with TimeSpan.Zero for timeout.
Cause
When using Ask, you must always specify a timeout value greater than TimeSpan.Zero otherwise the process might deadlock. See https://github.com/akkadotnet/akka.net/issues/6131 for details.
Important
This rule is not exhaustive - Roslyn can't scan every possible variable value at compilation time, so it's still possible to pass in a TimeSpan.Zero value even with this rule present.
An example:
using Akka.Actor;
using System.Threading.Tasks;
using System;
public static class MyActorCaller{
public static Task<string> Call(IActorRef actor){
return actor.Ask<string>(""hello"", TimeSpan.Zero);
}
}
Resolution
The right way to fix this issue is to pass in a non-zero value or to use the Ask<T> overload that accepts a CancellationToken.
Here's an example below:
using Akka.Actor;
using System.Threading.Tasks;
using System;
public static class MyActorCaller{
public static Task<string> Call(IActorRef actor){
return actor.Ask<string>(""hello"", TimeSpan.FromSeconds(1));
}
}
Edit this page