-
-
Notifications
You must be signed in to change notification settings - Fork 16.3k
Netty Epoll Bug occurs again (WorkAround Not working) #8306
Description
I'm using Netty 4.1.29.Final.
Java Version 1.8.0_181-b13
Amazon AMI Linux 4.9.119-44.140.amzn1.x86_64 (2017.09)
I' using lafaspot imapnio client which uses netty. [(https://github.com/lafaspot/imapnio)]
I'm running my Java App in Tomcat 8.5.29.
I get the following exception while shutting down the tomcat server.
The NIO threads are not being killed, causing a memory leak.
20-Sep-2018 13:07:36.516 WARNING [localhost-startStop-2] org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesThreads The web application [ROOT] appears to have started a thread named [IMAPNIO-THREAD-POOL-CUSTOM-1-1] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
sun.nio.ch.EPollArrayWrapper.epollWait(Native Method)
sun.nio.ch.EPollArrayWrapper.poll(EPollArrayWrapper.java:269)
sun.nio.ch.EPollSelectorImpl.doSelect(EPollSelectorImpl.java:93)
sun.nio.ch.SelectorImpl.lockAndDoSelect(SelectorImpl.java:86)
sun.nio.ch.SelectorImpl.select(SelectorImpl.java:97)
io.netty.channel.nio.SelectedSelectionKeySetSelector.select(SelectedSelectionKeySetSelector.java:62)
io.netty.channel.nio.NioEventLoop.select(NioEventLoop.java:737)
io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:392)
io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:884)
io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
java.lang.Thread.run(Thread.java:748)
20-Sep-2018 13:07:36.517 WARNING [localhost-startStop-2] org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesThreads The web application [ROOT] appears to have started a thread named [IMAPNIO-THREAD-POOL-CUSTOM-3-1] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
sun.nio.ch.EPollArrayWrapper.epollWait(Native Method)
sun.nio.ch.EPollArrayWrapper.poll(EPollArrayWrapper.java:269)
sun.nio.ch.EPollSelectorImpl.doSelect(EPollSelectorImpl.java:93)
sun.nio.ch.SelectorImpl.lockAndDoSelect(SelectorImpl.java:86)
sun.nio.ch.SelectorImpl.select(SelectorImpl.java:97)
io.netty.channel.nio.SelectedSelectionKeySetSelector.select(SelectedSelectionKeySetSelector.java:62)
io.netty.channel.nio.NioEventLoop.select(NioEventLoop.java:737)
io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:392)
io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:884)
io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
java.lang.Thread.run(Thread.java:748)
This is the code I'm using to create and shutdown threads:
`public class IMAPClient {
/** instance id used for debug. */
private final String instanceId = Integer.toString(new Random(System.nanoTime()).nextInt());
/** counter for session. */
private AtomicInteger sessionCounter = new AtomicInteger(1);
/** The netty bootstrap. */
private final Bootstrap bootstrap;
/** Event loop group that will serve all channels for IMAP client. */
private final EventLoopGroup group;
/**
* Constructs a NIO based IMAP client.
*
* @param threads number of threads to be used by IMAP client
*/
public IMAPClient(final int threads) {
this.bootstrap = new Bootstrap();
this.group = new NioEventLoopGroup(threads, new DefaultThreadFactory("IMAPNIO-THREAD-POOL-CUSTOM"));
bootstrap.channel(NioSocketChannel.class);
bootstrap.group(group);
}
/**
* Close all of the sessions within a client, and shutdown the event group.
*/
public void shutdown() {
Future<?> future = this.group.shutdownGracefully();
try {
if(future != null) {
future.await();
}
boolean isTerminated = this.group.awaitTermination(300, TimeUnit.SECONDS);
} catch (InterruptedException e) {
}
}
}`
I tried the workaround mentioned here https://netty.io/news/2012/09/13/4-0-0-alpha4.html
I added the -Dio.netty.epollBugWorkaround=true to JAVA_OPTS. But still I get this error.
Can you please tell me how to fix this error ?