diff --git a/src/core/Akka.Tests/Actor/AskTimeoutSpec.cs b/src/core/Akka.Tests/Actor/AskTimeoutSpec.cs index 61183d41aeb..af283ab74d1 100644 --- a/src/core/Akka.Tests/Actor/AskTimeoutSpec.cs +++ b/src/core/Akka.Tests/Actor/AskTimeoutSpec.cs @@ -50,5 +50,25 @@ public async Task Ask_should_honor_config_specified_timeout() } } + [Fact] + public async Task TimedOut_ask_should_remove_temp_actor() + { + var actor = Sys.ActorOf(); + + var actorCell = actor as ActorRefWithCell; + var container = actorCell.Provider.TempContainer as VirtualPathContainer; + try + { + await actor.Ask("should time out"); + } + catch (Exception) + { + var childCounter = 0; + container.ForEachChild(x => childCounter++); + Assert.True(childCounter==0,"Number of children in temp container should be 0."); + } + + } + } } diff --git a/src/core/Akka/Actor/Futures.cs b/src/core/Akka/Actor/Futures.cs index 3b17e978d91..613842ab274 100644 --- a/src/core/Akka/Actor/Futures.cs +++ b/src/core/Akka/Actor/Futures.cs @@ -66,15 +66,20 @@ private static Task Ask(ICanTell self, object message, IActorRefProvider timeout = timeout ?? provider.Settings.AskTimeout; + //create a new tempcontainer path + ActorPath path = provider.TempPath(); + if (timeout != Timeout.InfiniteTimeSpan && timeout.Value > default(TimeSpan)) { timeoutCancellation = new CancellationTokenSource(); - timeoutCancellation.Token.Register(() => result.TrySetCanceled()); + timeoutCancellation.Token.Register(() => + { + result.TrySetCanceled(); + provider.UnregisterTempActor(path); + }); timeoutCancellation.CancelAfter(timeout.Value); } - //create a new tempcontainer path - ActorPath path = provider.TempPath(); //callback to unregister from tempcontainer Action unregister = () =>