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

Possible memory leak when client adds/removes EntryListeners #5893

Closed
ttaomae opened this issue Aug 7, 2015 · 2 comments

Comments

Projects
None yet
4 participants
@ttaomae
Copy link

commented Aug 7, 2015

Below is a minimal working example which demonstrates the issue.

import com.hazelcast.config.Config;
import com.hazelcast.core.Hazelcast;

public class ListenerMember
{
    public static void main(String[] args) {
        new ListenerMember().run();
    }

    public void run() {
        Config cfg = new Config();
        Hazelcast.newHazelcastInstance(cfg);
    }
}
import com.hazelcast.client.HazelcastClient;
import com.hazelcast.client.config.ClientConfig;
import com.hazelcast.client.config.ClientNetworkConfig;
import com.hazelcast.core.HazelcastInstance;
import com.hazelcast.core.IMap;
import com.hazelcast.map.listener.MapListener;


public class ListenerClient implements MapListener
{
    public static void main(String[] args) {
        new ListenerClient().run();
    }

    public void run() {
        ClientNetworkConfig networkConfig = new ClientNetworkConfig();
        networkConfig.addAddress("127.0.0.1:5701");
        ClientConfig clientConfig = new ClientConfig();
        clientConfig.setNetworkConfig(networkConfig);
        HazelcastInstance client = HazelcastClient.newHazelcastClient(clientConfig);

        IMap<Integer, String> map = client.getMap("testmap");

        while (true) {
            final String listenerId = map.addEntryListener(this, false);
            map.removeEntryListener(listenerId);
        }
    }
}

ListenerMember was run for 1 minute before starting ListenerClient. The image below shows the heap usage of ListenerMember over the course of approximately 30 minutes, as reported by Java VisualVM.
cluster_member_heap

The test was run using versions 3.4.2, 3.5.1, and 3.6 snapshot (20150807.171323-259), and all version exhibited the same behavior. When using version 3.4, ListenerClient implemented EntryListener instead of MapListener (which was not available in 3.4)

The above image was produced using 3.6 snapshot, using Java 7 on a Windows 7 machine using the following JVM arguments: -server -Xms1G -Xmx1G. Similar behavior is exhibited when running a similar test using Hazelcast Simulator 0.5 across multiple CentOS 6.6 virtual machines.

@jerrinot

This comment has been minimized.

Copy link
Contributor

commented Aug 9, 2015

@ttaomae Thank you for reporting the issue. I can reproduce the behaviour.

It seems there is a leak in the ClientEndpointImpl.removeListenerActions collection. A clean-up task is inserted into the list on listener registration, but it seems it's not removed on de-registration.

image

@bwzhang2011

This comment has been minimized.

Copy link

commented Aug 25, 2015

@jerrinot, did you find the solution to fix the bug in ClientEndpointImpl ?

@sancar sancar self-assigned this Aug 28, 2015

sancar added a commit to sancar/hazelcast that referenced this issue Aug 31, 2015

Fixes memory leak in client listeners
Memory leak occurs when a listener added and removed from client.
A remove runnable in the collection that is stored in ClientEndpointImpl
is the leftover. This remove runnable collection was used to cleanup the
listeners when client is disconnected. With this change, listener removal
is always done via this remove runnables and runnable itself removed.

fixes hazelcast#5893

sancar added a commit to sancar/hazelcast that referenced this issue Aug 31, 2015

Fixes memory leak in client listeners
Memory leak occurs when a listener added and removed from client.
A remove runnable in the collection that is stored in ClientEndpointImpl
is the leftover. This remove runnable collection was used to cleanup the
listeners when client is disconnected. With this change, listener removal
is always done via this remove runnables and runnable itself removed.

fixes hazelcast#5893

sancar added a commit to sancar/hazelcast that referenced this issue Aug 31, 2015

Fixes memory leak in client listeners
Memory leak occurs when a listener added and removed from client.
A remove runnable in the collection that is stored in ClientEndpointImpl
is the leftover. This remove runnable collection was used to cleanup the
listeners when client is disconnected. With this change, listener removal
is always done via this remove runnables and runnable itself removed.

fixes hazelcast#5893

sancar added a commit to sancar/hazelcast that referenced this issue Aug 31, 2015

Fixes memory leak in client listeners
Memory leak occurs when a listener added and removed from client.
A remove runnable in the collection that is stored in ClientEndpointImpl
is the leftover. This remove runnable collection was used to cleanup the
listeners when client is disconnected. With this change, listener removal
is always done via this remove runnables and runnable itself removed.

fixes hazelcast#5893

sancar added a commit to sancar/hazelcast that referenced this issue Sep 1, 2015

Fixes memory leak when using client listeners
Memory leak occurs when a listener added and removed from client.
A remove runnable in the collection that is stored in ClientEndpointImpl
is the leftover. Deletion of this remove actions is moved to
AbstractRemoveListenerMessageTask for new client and
BaseClientRemoveListenerRequest for old client.

fixes hazelcast#5893

sancar added a commit to sancar/hazelcast that referenced this issue Sep 1, 2015

Fixes memory leak when using client listeners
Memory leak occurs when a listener added and removed from client.
A remove runnable in the collection that is stored in ClientEndpointImpl
is the leftover. Deletion of this remove actions is moved to
AbstractRemoveListenerMessageTask for new client and
BaseClientRemoveListenerRequest for old client.

fixes hazelcast#5893

sancar added a commit to sancar/hazelcast that referenced this issue Sep 9, 2015

Fixes memory leak when using client listeners
Memory leak occurs when a listener added and removed from client.
A remove runnable in the collection that is stored in ClientEndpointImpl
is the leftover. Deletion of this remove actions is moved to
AbstractRemoveListenerMessageTask for new client and
BaseClientRemoveListenerRequest for old client.

fixes hazelcast#5893

sancar added a commit to sancar/hazelcast that referenced this issue Sep 9, 2015

Fixes memory leak when using client listeners
Memory leak occurs when a listener added and removed from client.
A remove runnable in the collection that is stored in ClientEndpointImpl
is the leftover. Deletion of this remove actions is moved to
AbstractRemoveListenerMessageTask for new client and
BaseClientRemoveListenerRequest for old client.

fixes hazelcast#5893

@sancar sancar closed this in #6097 Sep 17, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.