Akka.Actor: Context.Watch on FutureActorRef<T> creates memory leaks#7502
Conversation
|
With 100% certainty, we will need to run the |
Aaronontheweb
left a comment
There was a problem hiding this comment.
Reviewed my changes - still need benchmarks
| } | ||
|
|
||
| [Fact] | ||
| public async Task FutureActorRefShouldSupportDeathWatch() |
There was a problem hiding this comment.
Handles both scenarios:
Context.Watchbefore theFutureActorRef<T>completesContext.Watchafter theFutureActorRef<T>has already completed, which should immediately report back with aTerminatedmessage
| /// <summary> | ||
| /// INTERNAL API - didn't want static helper methods declared inside generic class | ||
| /// </summary> | ||
| internal static class FutureActorRefDeathWatchSupport |
There was a problem hiding this comment.
Helper class for sending back ISystemMsgs from FutureActorRef<T>
|
|
||
| switch (message) | ||
| { | ||
| case ISystemMessage msg: |
There was a problem hiding this comment.
As mentioned in #7501, this code never worked because it was in the wrong method. Removing it should actually speed up Ask<T> processing slightly.
| { | ||
| if (_result.Task.IsCompleted) | ||
| { | ||
| watch.Watcher.SendSystemMessage(FutureActorRefDeathWatchSupport.TerminatedFor(this)); |
There was a problem hiding this comment.
Fast path: this actor is already "finished"
| } | ||
| else | ||
| { | ||
| _ = FutureActorRefDeathWatchSupport.ScheduleDeathWatch(watch.Watcher, watch.Watchee, _result.Task); |
There was a problem hiding this comment.
Slow path - have to wait for actor to finish
| { | ||
| if (message is Watch watch) | ||
| { | ||
| if (_result.Task.IsCompleted) |
There was a problem hiding this comment.
Automatically covers any possible completion state for the task: cancelled, faulted, or ran to completion
| } | ||
| catch | ||
| { | ||
| // we don't do error handling for this - we do not care |
There was a problem hiding this comment.
Error-handling is the job of the user code await-ing on the Ask - not ours.
|
No real performance impact, but there are some failing tests that need to be addressed |
Changes
Fixes #7501
Checklist
For significant changes, please ensure that the following have been completed (delete if not relevant):
FutureActorRef<T>does not supportContext.Watchand may cause memory leaks #7501Latest
devBenchmarksThis PR's Benchmarks