mina-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Guillaume Nodet (JIRA)" <j...@apache.org>
Subject [jira] [Updated] (SSHD-646) ThreadGroup created in ThreadUtils is not destroyed and causes memory leak
Date Wed, 09 Mar 2016 10:29:40 GMT

     [ https://issues.apache.org/jira/browse/SSHD-646?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel

Guillaume Nodet updated SSHD-646:
    Fix Version/s: 1.1.1

> ThreadGroup created in ThreadUtils is not destroyed and causes memory leak
> --------------------------------------------------------------------------
>                 Key: SSHD-646
>                 URL: https://issues.apache.org/jira/browse/SSHD-646
>             Project: MINA SSHD
>          Issue Type: Bug
>    Affects Versions: 1.0.0
>         Environment: linux
>            Reporter: Ke Xu
>            Assignee: Goldstein Lyor
>             Fix For: 1.2.0, 1.1.1
>   Original Estimate: 8h
>  Remaining Estimate: 8h
> ===============
> Problem description
> ===============
> In our application, we found that more than 250M memory were occupied by around 700,000
ThreadGroup objects (whose names are SshClient-nio2, timer, ClientInputStreamPump). The Threads
contained in these ThreadGroups and their sub groups were all null.
> ===============
> Analysis
> ===============
> In ThreadUtils class there is an inner class named SshdThreadFactory. Inside this class,
it will create a ThreadGroup and attach it to the parent Threadgroup: 
> group = new ThreadGroup(parentGroup, "sshd-" + effectiveName + "-group");
> However, the destroy() method of the ThreadGroup object is never explicitely called when
relevent resources are closed. 
> According to ThreadGroup API, when a ThreadGroup is created with parent ThreadGroup specified,
a reference to this child ThreadGroup is created in the parent. The destroy() method is the
only way to make the parent to remove this reference. 
> Thus in case the parent ThreadGroup is main, and there is a lot of ThreadGroup created,
the ThreadGoup objects are not collected by the system until program exits. It will eventually
occupy a lot of memory.
> ===============
> Suggested solution
> ===============
> A suggested solution is to mark the ThreadGroup object as daemon after it is created
in SshdThreadFactory, e.g.:
>             group = new ThreadGroup(parentGroup, "sshd-" + effectiveName + "-group");
>             group.setDaemon(true); 
> According to API, when a ThreadGroup is marked as daemon, it is automatically destroyed
when its last thread is stopped or its last thread group is destroyed.

This message was sent by Atlassian JIRA

View raw message