Possible memory leak when client adds/removes EntryListeners #5893

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

Projects

None yet

4 participants

@ttaomae
ttaomae 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 jerrinot added this to the 3.6 milestone Aug 9, 2015
@jerrinot
Contributor
jerrinot 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

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

@sancar sancar self-assigned this Aug 28, 2015
@sancar sancar added a commit to sancar/hazelcast that referenced this issue Aug 31, 2015
@sancar sancar 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 #5893
2f81494
@sancar sancar added a commit to sancar/hazelcast that referenced this issue Aug 31, 2015
@sancar sancar 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 #5893
01d4cdc
@sancar sancar added a commit to sancar/hazelcast that referenced this issue Aug 31, 2015
@sancar sancar 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 #5893
46e7225
@sancar sancar added a commit to sancar/hazelcast that referenced this issue Aug 31, 2015
@sancar sancar 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 #5893
7324f14
@sancar sancar added a commit to sancar/hazelcast that referenced this issue Sep 1, 2015
@sancar sancar 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 #5893
c738f78
@sancar sancar added a commit to sancar/hazelcast that referenced this issue Sep 1, 2015
@sancar sancar 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 #5893
f16e227
@sancar sancar added a commit to sancar/hazelcast that referenced this issue Sep 9, 2015
@sancar sancar 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 #5893
f1a83ed
@sancar sancar added a commit to sancar/hazelcast that referenced this issue Sep 9, 2015
@sancar sancar 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 #5893
d65de87
@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