Skip to content
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

Fix memory leak caused by QueryThrottler #518

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from

Conversation

Arkatufus
Copy link
Contributor

Fixes #516

Changes

Make sure we don't death watch Ask temp actors

Checklist

For significant changes, please ensure that the following have been completed (delete if not relevant):

Copy link
Contributor Author

@Arkatufus Arkatufus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Self-review

Comment on lines -55 to -59
using var cts = CancellationTokenSource.CreateLinkedTokenSource(state.ShutdownToken);
{
cts.CancelAfter(state.QueryThrottleTimeout);
await state.QueryPermitter.Ask<QueryStartGranted>(RequestQueryStart.Instance, cts.Token);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove complicated cancellation token code, replaced it with Ask internal timeout mechanism

Comment on lines +117 to +121
if(Sender is ActorRefWithCell)
{
_watchCount++;
Context.Watch(Sender);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actual fix, never watch any IActorRef with no ActorCell, these actors are not compatible with death watch.

_pending.RemoveFirst();
QueryStartGranted(popRef);
if (pending is not null && pending.IsExpired)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we can't rely on death watch mechanism to automatically purge pending requests, we have to add timeout deadlines to the pending requests. All expired pending requests will be discarded.

Copy link
Member

@to11mtm to11mtm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

left a few questions/comments, great work digging into it. At most it's future improvement in my head...

/// Works identically to the RecoveryPermitter built into Akka.Persistence.
/// Works almost identically to the RecoveryPermitter built into Akka.Persistence.
///
/// NOTE: Since this permitter works with Ask and we can't death watch an Ask temp
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice if we could encapsulate/sugar this behavior in future, that said comment is great breadcrumb for future improvement.


if (_usedPermits < 0)
throw new IllegalStateException("Permits must not be negative");
{
_log.Warning("Permits must not be negative");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it overkill to include the negative value here? Also what justifies the reset to zero?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its a warning for the developers. It should not kill the actor outright, and the throttler should keep on going. If the value goes negative, this means that we over-return permits, something is returning more permits than what was issued. Its not a critical error, the actor should work regardless, but we should take a note of it happening.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Memory Leak after updating Akka from 1.5.27.1 to 1.5.37
2 participants