graylog-labs/log4j2-gelf

using this in tomcat app causes memory leak

highcourter opened this issue · 3 comments

using latest version 1.0.3 in a tomcat 7 webapp and working fine so far. When stopping the tomcat service catalina.out reports on threads it couldn't stop:

Apr 21, 2015 1:52:32 PM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
Schwerwiegend: The web application [/myapp] appears to have started a thread named [nioEventLoopGroup-2-1] but has failed to stop it. This is very likely to create a
memory leak.

Apr 21, 2015 1:52:32 PM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
Schwerwiegend: The web application [/myapp] appears to have started a thread named [GelfSenderThread-37] but has failed to stop it. This is very likely to
create a memory leak.

Apr 21, 2015 1:52:32 PM org.apache.catalina.loader.WebappClassLoader checkThreadLocalMapForLeaks
Schwerwiegend: The web application [/myapp] created a ThreadLocal with key of type [java.lang.ThreadLocal](value [java.lang.ThreadLocal@5f9e0bcf])
and a value of type [io.netty.util.internal.InternalThreadLocalMap](value [io.netty.util.internal.InternalThreadLocalMap@1197414]) but failed to remove it when the
web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.

Apr 21, 2015 1:52:32 PM org.apache.catalina.loader.WebappClassLoader checkThreadLocalMapForLeaks
Schwerwiegend: The web application [/myapp] created a ThreadLocal with key of type [java.lang.ThreadLocal](value [java.lang.ThreadLocal@5f9e0bcf]) and a value of
type [io.netty.util.internal.InternalThreadLocalMap](value [io.netty.util.internal.InternalThreadLocalMap@2e13cd9c]) but failed to remove it when the web
application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.

this is proven to be only since the GelfAppender was added. It is no problem when that appender is disabled anymore.
any idea how to make the GelfAppender shutdown gracefully?

Could you please try to reproduce this warning with the freshly released version 1.1.0 of log4j2-gelf?

The internally used GELF client has been updated to version 1.3.0 which is now using daemon threads (see Graylog2/gelfclient#8).

Thanks for this update.

I just discovered the same problem with the GelfSenderThread keeping the JVM alive on shutdown (although it wasn't in a Tomcat environment).

Updating from 1.0.3 to 1.1.0 fixed this for me and it shuts down gracefully now.

Thanks for letting us know!