-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Akka.Actor: Context.Watch on FutureActorRef<T> creates memory leaks
#7502
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
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed my changes - still need benchmarks
| } | ||
|
|
||
| [Fact] | ||
| public async Task FutureActorRefShouldSupportDeathWatch() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Helper class for sending back ISystemMsgs from FutureActorRef<T>
|
|
||
| switch (message) | ||
| { | ||
| case ISystemMessage msg: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fast path: this actor is already "finished"
| } | ||
| else | ||
| { | ||
| _ = FutureActorRefDeathWatchSupport.ScheduleDeathWatch(watch.Watcher, watch.Watchee, _result.Task); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
Arkatufus
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
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