Memory leak on Agent when connection to the CMR is not available

Description

The sprIT team has reported that they have a memory leak when running the agent for some amount of time without it being connected to the CMR. Although this is not a real usage scenario for us (why would Agent be there without the CMR), I still had a look on the heap dump they provided. And they were correct the Agent does make a memory leak.

Apparently every time we try to connect to the CMR we create a new instance of the kryonet Client for communication. If connect fails we do allow this object to be garbage collected, but it's obviously not collected.. Seams like the problem is that Client creates a thread when being constructed (Client thread) and this one has a hard reference to the Client itself. And this thread seams to stay alive although we call clearly Client.stop() method when connection fails.

In my opinion we have two options here:

  1. Keep current approach, but check how to terminate the update thread as well (maybe calling Client.close()) as well.

  2. Create only one client instance and just executed connect() method when connection is asked for

Environment

None

Activity

Show:
Ivan Senic
March 23, 2016, 10:31 AM

Attached the screens from MAT.. As it can be seen we have 653 instances of Client object.. And the GC root path shows that only reference to the Client is the thread itself..

Ivan Senic
March 23, 2016, 11:00 AM

Update: The threads are not terminated not because we are doing something wrong, but because they hit the ePoolWait() method (see updated pic). Most likely they hit this method during the close method or something like this.. I will try to test to see if we can avoid this..

Patrice Bouillet
March 23, 2016, 12:02 PM

which updated pic are you referring to?

Patrice Bouillet
April 15, 2016, 12:22 PM
Ivan Senic
April 15, 2016, 12:26 PM

Pushed before commit.. Sorry..

Assignee

Ivan Senic

Reporter

Ivan Senic

Labels

None

Integrator

Patrice Bouillet

Sprint

None

Fix versions

Affects versions

Priority

Highest
Configure