简体   繁体   中英

Netty server shutdown exception

I have used to following code to handle server shutdown:

public void stop() {
    try {
        this.channelFuture.channel().close();
        this.channelFuture.channel().closeFuture().sync();
    } catch (InterruptedException e) {
        Log.exceptionStack(e);
    } finally {
        this.bootstrap.config().childGroup().shutdownGracefully(10, 30, TimeUnit.SECONDS);
        this.bootstrap.config().group().shutdownGracefully(5, 10, TimeUnit.SECONDS);
    }
}

Sometimes the server shutsdown with the following exception:

Exception in thread "nioEventLoopGroup-3-1" java.lang.NoClassDefFoundError: io/netty/buffer/PoolArena$1
        at io.netty.buffer.PoolArena.freeChunk(PoolArena.java:293)
        at io.netty.buffer.PoolThreadCache$MemoryRegionCache.freeEntry(PoolThreadCache.java:471)
        at io.netty.buffer.PoolThreadCache$MemoryRegionCache.free(PoolThreadCache.java:441)
        at io.netty.buffer.PoolThreadCache$MemoryRegionCache.free(PoolThreadCache.java:433)
        at io.netty.buffer.PoolThreadCache.free(PoolThreadCache.java:290)
        at io.netty.buffer.PoolThreadCache.free(PoolThreadCache.java:281)
        at io.netty.buffer.PoolThreadCache.free0(PoolThreadCache.java:254)
        at io.netty.buffer.PoolThreadCache.free(PoolThreadCache.java:250)
        at io.netty.buffer.PooledByteBufAllocator$PoolThreadLocalCache.onRemoval(PooledByteBufAllocator.java:431)
        at io.netty.buffer.PooledByteBufAllocator$PoolThreadLocalCache.onRemoval(PooledByteBufAllocator.java:408)
        at io.netty.util.concurrent.FastThreadLocal.remove(FastThreadLocal.java:226)
        at io.netty.util.concurrent.FastThreadLocal.removeAll(FastThreadLocal.java:67)
        at io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:146)
        at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.ClassNotFoundException: io.netty.buffer.PoolArena$1
        at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
        ... 14 more
Exception in thread "Thread-1" java.lang.NoClassDefFoundError: io/netty/channel/AbstractChannelHandlerContext$13
        at io.netty.channel.AbstractChannelHandlerContext.close(AbstractChannelHandlerContext.java:610)
        at io.netty.channel.AbstractChannelHandlerContext.close(AbstractChannelHandlerContext.java:465)
        at io.netty.channel.DefaultChannelPipeline.close(DefaultChannelPipeline.java:964)
        at io.netty.channel.AbstractChannel.close(AbstractChannel.java:234)
        at co.gps.smaartly.TrackerServer.stop(TrackerServer.java:59)
        at co.gps.smaartly.ServerManager.stop(ServerManager.java:90)
        at co.gps.smaartly.App$1.run(App.java:22)
Caused by: java.lang.ClassNotFoundException: io.netty.channel.AbstractChannelHandlerContext$13
        at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
        ... 7 more

I am using netty version 4.1.9.Final on JVM version:

java version "1.8.0_121"
Java(TM) SE Runtime Environment (build 1.8.0_121-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)

On Ubuntu 16.04

Please help me identify the issue here. Let me know if any other details are required.

This is most likely because the jar is unloaded before the shutdown is 100 % complete. .shutdownGracefully(...) is asynchronous so you should use .shutdownGracefully(...).sync() here.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM