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

Client and server memory leaks while destroying FencedLocks [HZ-3039] #25344

Closed
arodionov opened this issue Aug 31, 2023 · 2 comments · Fixed by #25353
Closed

Client and server memory leaks while destroying FencedLocks [HZ-3039] #25344

arodionov opened this issue Aug 31, 2023 · 2 comments · Fixed by #25353

Comments

@arodionov
Copy link
Contributor

arodionov commented Aug 31, 2023

The local FencedLock proxy object is not removed from LockService#proxies map while the Lock#destroy() called

Steps to reproduce:

        HazelcastInstance instance = Hazelcast.newHazelcastInstance(config);
        Hazelcast.newHazelcastInstance(config);
        Hazelcast.newHazelcastInstance(config);
        CPSubsystem cpSubsystem = instance.getCPSubsystem();

        for (int i = 0; i < 100; i++) {
            FencedLock lock = cpSubsystem.getLock("iLock_" + i);
            lock.lock();
            lock.unlock();
            lock.destroy();
        }

The LockService#proxies map contains 100 FencedLockProxy objects:

image

This behaviour causes memory leaks.

The same behaviour is also on the client side: the ClientRaftProxyFactory#lockProxies tracks all created FencedLockProxy and not remove from the map.

The same client-side _lock_proxies map can be found in the Python client https://github.com/hazelcast/hazelcast-python-client/blob/master/hazelcast/cp.py#L198

@arodionov arodionov added this to the 5.4 Backlog milestone Aug 31, 2023
@arodionov arodionov changed the title Memory leak while destroying local FencedLockProxy Memory leak while destroying local FencedLock Aug 31, 2023
@arodionov arodionov changed the title Memory leak while destroying local FencedLock Memory leak while destroying FencedLock Aug 31, 2023
@arodionov arodionov changed the title Memory leak while destroying FencedLock Clint and server memory leaks while destroying FencedLock Aug 31, 2023
@arodionov arodionov changed the title Clint and server memory leaks while destroying FencedLock Client and server memory leaks while destroying FencedLocks Aug 31, 2023
@gbarnett-hz
Copy link
Contributor

gbarnett-hz commented Sep 1, 2023

From code we only tidy LockService.proxies up under the following scenarios:

  1. CP system restart, LockService#onCPSubsystemRestart(); and
  2. When a proxy with the same name already exists but is associated with an unexpected CP group ID

Doesn't look like proxies mapping is critical to other semantics.

If the current semantics of not permitting the same object to be reused post-destruction are to be preserved and we don't want the removal from proxies to deviate from current semantics, then @arodionov is it possible the safest (read: most conservative) place to perform the removal would be after we add the object name to ResourceRegistry.destroyedNames? Looking at the code I think this could be done earlier but not sure if that will have some unknown side effect.

As a sketch:

class LockService ... {
    // ...
    @Override
    public boolean destroyRaftObject(CPGroupId groupId, String name) {
        boolean result = super.destroyRaftObject(groupId, name);
        FencedLockProxy proxy = proxies.get(name);
        proxies.remove(name, proxy);
        return result;
    }
}

@gbarnett-hz gbarnett-hz self-assigned this Sep 1, 2023
@github-actions github-actions bot changed the title Client and server memory leaks while destroying FencedLocks Client and server memory leaks while destroying FencedLocks [HZ-3039] Sep 1, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Sep 1, 2023

Internal Jira issue: HZ-3039

gbarnett-hz added a commit that referenced this issue Sep 6, 2023
…3039] (#25353)

Removes the `FencedLockProxy` from `LockService.proxies` _after_ calling
legacy semantics of `AbstractBlockingService#destroyRaftObject`.
Previously the `FencedLockProxy` would be resident in
`LockService.proxies` until the CP system was reset.

Fixes #25344
gbarnett-hz added a commit to gbarnett-hz/hazelcast that referenced this issue Sep 12, 2023
…3039] (hazelcast#25353)

Removes the `FencedLockProxy` from `LockService.proxies` _after_ calling
legacy semantics of `AbstractBlockingService#destroyRaftObject`.
Previously the `FencedLockProxy` would be resident in
`LockService.proxies` until the CP system was reset.

Fixes hazelcast#25344

(cherry picked from commit e301940)
gbarnett-hz added a commit that referenced this issue Sep 12, 2023
…3039] [5.3.z] (#25421)

Removes the `FencedLockProxy` from `LockService.proxies` _after_ calling
legacy semantics of `AbstractBlockingService#destroyRaftObject`.
Previously the `FencedLockProxy` would be resident in
`LockService.proxies` until the CP system was reset.

Fixes #25344 

Backport of: #25353
@AyberkSorgun AyberkSorgun modified the milestones: 5.4 Backlog, 5.4.0 Mar 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants