title: Exception during Netty server shutdown
body: <p>I have application running on Tomcat. I use Netty 4 for websocket handling.
  Netty server run in ServletContextListener in contextInitialized method and stop in contextDestroyed.</p>
  
  <p>This my class for Netty server:</p>
  
  <pre><code>public class WebSocketServer {
  
      private final int port;
      private final EventLoopGroup bossGroup;
      private final EventLoopGroup workerGroup;
      private Channel serverChannel;
  
      public WebSocketServer(int port) {
          this.port = port;
          bossGroup = new NioEventLoopGroup(1);
          workerGroup = new NioEventLoopGroup();
      }
  
      public void run() throws Exception {
          final ServerBootstrap b = new ServerBootstrap();
          b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class)
                  .childHandler(new WebSocketServerInitializer());
          serverChannel = b.bind(port).sync().channel();
          System.out.println("Web socket server started at port " + port + '.');
          System.out
                  .println("Open your browser and navigate to http://localhost:"
                          + port + '/');
      }
  
      public void stop() {
          if (serverChannel != null) {
              ChannelFuture chFuture = serverChannel.close();
              chFuture.addListener(new ChannelFutureListener() {
  
                  @Override
                  public void operationComplete(ChannelFuture future) throws Exception {
                      shutdownWorkers();
  
                  }
              });
          } else {
              shutdownWorkers();
          }
      }
  
      private void shutdownWorkers() {
          bossGroup.shutdownGracefully();
          workerGroup.shutdownGracefully();
      }
  }
  </code></pre>
  
  <p>It's work fine after running, but when I try stop Tomcat I get exception:</p>
  
  <p>INFO: Illegal access: this web application instance has been stopped already.  Could not load io.netty.util.concurrent.DefaultPromise$3.  The eventual following stack trace is caused by an error thrown for debugging purposes as well as to attempt to terminate the thread which caused the illegal access, and has no functional impact.
  java.lang.IllegalStateException
      at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1610)
      at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1569)
      at io.netty.util.concurrent.DefaultPromise.notifyListeners(DefaultPromise.java:592)
      at io.netty.util.concurrent.DefaultPromise.setSuccess(DefaultPromise.java:403)
      at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:139)
      at java.lang.Thread.run(Thread.java:662)</p>
  
  <p>After Tomcat hangs up.
  What can be reason?</p>