Repository: netty/netty
Issue: Infinite Selector rebuild loop of death.

I'm experiencing an issue that has been reported about before. None of the reports are giving me any hints though. (e.g. #2426 and #2616)

The problem: I'm starting a Websocket server with ServerBootstrap bound to the wifi IP address on Android. As soon the wifi connection changes or wifi is disabled completely, the log will be flooded with the following two messages, repeated about 100 times per second while the app is not usable anymore.

```
W/NioEventLoop: Selector.select() returned prematurely 512 times in a row; rebuilding Selector sun.nio.ch.PollSelectorImpl@e54f195.
I/NioEventLoop: Migrated 1 channel(s) to the new Selector.
```

### Steps to reproduce
Run the below code on an android device and while the app is running switch off wifi or change to another wifi hotspot.

### Minimal yet complete reproducer code (or URL to code)

``` java
import android.content.Context;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

import com.google.common.net.InetAddresses;

import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.nio.ByteOrder;

import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioServerSocketChannel;
import io.netty.handler.codec.http.HttpServerCodec;

public class MainActivity extends AppCompatActivity {
    private EventLoopGroup group;
    protected InetSocketAddress localAddress;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        localAddress = new InetSocketAddress(getLocalIPAddress(this), 0);
        group = new NioEventLoopGroup();
        ServerBootstrap tcp = new ServerBootstrap();

        tcp.group(group)
            .channel(NioServerSocketChannel.class)
            .childHandler(new ChannelInitializer() {
                @Override
                protected void initChannel(Channel ch) throws Exception {
                    addLast("server",
                            ch.pipeline(),
                            new HttpServerCodec()
                    );
                }
            });

        tcp.bind(localAddress);

        ChannelFuture future = tcp.bind(localAddress);
        try {
            future.sync();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    public static void addLast(String prefix, ChannelPipeline pipeline, ChannelHandler... channelHandlers) {
        for (ChannelHandler handler : channelHandlers) {
            String name = (prefix + handler.getClass().getSimpleName()).intern();
            pipeline.addLast(name, handler);
        }
    }

    protected EventLoopGroup newEventLoopGroup(int maxChannels) {
        return new NioEventLoopGroup(maxChannels);
    }

    protected final EventLoopGroup newEventLoopGroup() {
        return newEventLoopGroup(0);
    }

    public static InetAddress getLocalIPAddress(Context context) {
        WifiManager wifiManager = (WifiManager) context.getSystemService(WIFI_SERVICE);
        WifiInfo wifiInfo = wifiManager.getConnectionInfo();
        int ip = wifiInfo.getIpAddress();
        if (ByteOrder.nativeOrder().equals(ByteOrder.LITTLE_ENDIAN)) {
            ip = Integer.reverseBytes(ip);
        }
        return InetAddresses.fromInteger(ip);
    }
}
```

```
dependencies {
    ...
    implementation 'io.netty:netty-codec-http:4.1.22.Final'
    implementation 'io.netty:netty-handler:4.1.22.Final'
    implementation 'com.google.guava:guava:20.0'
    ...
}
```

### Netty version
4.1.22.Final

### JVM version (e.g. `java -version`)
7

### OS version (e.g. `uname -a`)
Android 7.0


Issue comments:
Thats interesting... @carl-mastrangelo @ejona86 maybe you have some contacts we can loop in ? Generally speaking I think this should not happen as it woke-up the selector without reporting any events that need to be handled.
CC @ericgribkoff
This is reproducible on Android 8 for me as well. `selector.select()` returns immediately with OP_ACCEPT on the selected key set, then invoking `accept()` triggers an "Invalid argument" IOException from native code, and this just repeats indefinitely. I'm following up with some Android system folks about this, will update here if I get any additional information.
@ericgribkoff thanks a lot! Also let us know if there is any workaround we can add in the meantime (I suspect there is none tho :( ).
@normanmaurer From reading the code, I don't think it makes sense to continue trying to accept on the socket.   You get back EINVAL   which means it isn't listening anymore.

@jox : any reason you aren't listening on all addresses?  That would probably be more stable.
I wonder if this can work around the problem here: https://github.com/netty/netty/pull/7806.

@carl-mastrangelo the idea of continue reading here is that we also may get a `ENFILE` from which you can recover. That said I hope  https://github.com/netty/netty/pull/7806 will "workaround" the issue. Please check 
@jox can you test #7806 ?
@normanmaurer one possibility is to map the error message back to the errno, since OpenJDK directly uses the message from `strerror_r`.  This isn't a great solution, but it's feasible.
I hope this was fixed by #7806 . If not please re-open
I still have this issue on windows. I am using the following
```
Windows 10 Pro - 1803
JVM 1.8.0_111 HotSpot
Netty version 4.1.24.Final
```
I use [Ktor](https://github.com/ktorio/ktor) with Netty as the engine. My implementation:
```kotlin
fun main(args: Array<String>) {
    embeddedServer(Netty, port = 8080) {
        routing {
            get("/test") {
                call.respondText("Hello world")
            }
        }
    }.start(true)
}
```
It only happens when I test it with apache benchmark with Keep-Alive option enabled.
```
ab -k -n 100000 -c 500 http://localhost:8080/test
```

All the results seem to be passing, so the following error seems to happen after the connection closes:
```
[nettyCallPool-4-20] WARN io.netty.channel.nio.NioEventLoop - Selector.select() returned prematurely 512 times in a row; rebuilding Selector io.netty.channel.nio.SelectedSelectionKeySetSelector@61246795.
```

Also when I limit `connectionGroupSize`  to 1 (default on my machine is 5) the error is not showing up anymore:
```kotlin
embeddedServer(Netty, port = 8080, configure = {
        connectionGroupSize = 1
    })
```

@adhesivee can you also reproduce on linux or Mac ?
I tried it on linux and could not reproduce. I have no Mac to test on.
@adhesivee bummer... I will need to setup a windows vm then and try to reproduce.  Would be useful if you could commit a full reproducer that I can run to GitHub and link it here.
I created a setup which causes the issue on my machine: https://github.com/adhesivee/ktor-hello-sample
@adhesivee I can not reproduce on windows server 2012. Can you tell me which ab version you use ?
I am using:
```
This is ApacheBench, Version 2.3 <$Revision: 1748469 $>
```
hmm ... I am using

```
C:\Workspaces\Apache24\bin>ab.exe -V
This is ApacheBench, Version 2.3 <$Revision: 1826891 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.ne
Licensed to The Apache Software Foundation, http://www.apache.org/
```

All just works :(
One note though I did not get these exception while the debugger was enabled. 
And it only happened with Keep-Alive. Still I don't think it causes to much harm, because it seems to happen after the connection closes.
@adhesivee does it happen all the time ?
Also do I need to setup any logging etc to see it ?
The default logging (info level) is enough to see it. 
It does not always happen on the first ab run, but on the second run I always have quite some messages.
very odd... I am running it in a loop at the moment and did not see it yet ... 
@adhesivee would it be possible to share a thread dump / head dump when it happens ?

It would also be good if you could try to run with `-Dio.netty.selectorAutoRebuildThreshold=100000000` and check the cpu usage. In this case when the "problem" happens you should see a very high cpu usage. Once this happens I would like to see a thread dump / heap dump.
Is this format ok?
[heapdump-1536236928163.zip](https://github.com/netty/netty/files/2357016/heapdump-1536236928163.zip)

Yes this format is good... The important would be to have it taken when it happens.
I think it is captures but I am not sure. Sometimes the logger writes a moment later then when the event really happens, to make things more complicated ofcourse.
@adhesivee thats why I asked to run with "-Dio.netty.selectorAutoRebuildThreshold=100000000". This way you should detect the CPU usage goes up and then you can take the dump... That said it will not log then.
Ok I have done as you said. I have done 2 dumps in the same process while processor being at 100%.
I also change the benchmark a bit, this gives me the most of the messages:
```
ab -k -n 200000 -c 100 http://localhost:8080/test
```
[heapdump-1536237736820.zip](https://github.com/netty/netty/files/2357053/heapdump-1536237736820.zip)

@adhesivee cool thanks! Can I also have a few thread-dumps using `jstack` of the time it happens ?
I am not that familiar with `jstack` I ran it like this
```
jstack -J-d64 -m -l 6124
```

The output I got is this:
```
Attaching to process ID 6124, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.111-b14
Deadlock Detection:

No deadlocks found.

----------------- 0 -----------------
0x00007fffdcd69f34      ntdll!NtWaitForSingleObject + 0x14
0xec8b485741564155              ????????
sun.jvm.hotspot.debugger.DebuggerException: Windbg Error: ReadVirtual failed!
        at sun.jvm.hotspot.debugger.windbg.WindbgDebuggerLocal.readBytesFromProcess0(Native Method)
        at sun.jvm.hotspot.debugger.windbg.WindbgDebuggerLocal.readBytesFromProcess(WindbgDebuggerLocal.java:490)
        at sun.jvm.hotspot.debugger.DebuggerBase$Fetcher.fetchPage(DebuggerBase.java:80)
        at sun.jvm.hotspot.debugger.PageCache.getPage(PageCache.java:178)
        at sun.jvm.hotspot.debugger.PageCache.getLong(PageCache.java:100)
        at sun.jvm.hotspot.debugger.DebuggerBase.readCInteger(DebuggerBase.java:364)
        at sun.jvm.hotspot.debugger.DebuggerBase.readAddressValue(DebuggerBase.java:462)
        at sun.jvm.hotspot.debugger.windbg.WindbgDebuggerLocal.readAddress(WindbgDebuggerLocal.java:316)
        at sun.jvm.hotspot.debugger.windbg.WindbgAddress.getAddressAt(WindbgAddress.java:72)
        at sun.jvm.hotspot.debugger.windows.amd64.WindowsAMD64CFrame.sender(WindowsAMD64CFrame.java:60)
        at sun.jvm.hotspot.tools.PStack.run(PStack.java:161)
        at sun.jvm.hotspot.tools.PStack.run(PStack.java:58)
        at sun.jvm.hotspot.tools.PStack.run(PStack.java:53)
        at sun.jvm.hotspot.tools.JStack.run(JStack.java:66)
        at sun.jvm.hotspot.tools.Tool.startInternal(Tool.java:260)
        at sun.jvm.hotspot.tools.Tool.start(Tool.java:223)
        at sun.jvm.hotspot.tools.Tool.execute(Tool.java:118)
        at sun.jvm.hotspot.tools.JStack.main(JStack.java:92)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at sun.tools.jstack.JStack.runJStackTool(JStack.java:140)
        at sun.tools.jstack.JStack.main(JStack.java:106)
----------------- 1 -----------------
----------------- 2 -----------------
0x00007fffdcd69f34      ntdll!NtWaitForSingleObject + 0x14
Locked ownable synchronizers:
    - None
----------------- 3 -----------------
----------------- 4 -----------------
----------------- 5 -----------------
----------------- 6 -----------------
----------------- 7 -----------------
----------------- 8 -----------------
----------------- 9 -----------------
----------------- 10 -----------------
----------------- 11 -----------------
0x00007fffdcd69f34      ntdll!NtWaitForSingleObject + 0x14
----------------- 12 -----------------
0x00007fffdcd69f34      ntdll!NtWaitForSingleObject + 0x14
Locked ownable synchronizers:
    - None
----------------- 13 -----------------
0x00007fffdcd69f34      ntdll!NtWaitForSingleObject + 0x14
Locked ownable synchronizers:
    - None
----------------- 14 -----------------
0x00007fffdcd69f34      ntdll!NtWaitForSingleObject + 0x14
Locked ownable synchronizers:
    - None
----------------- 15 -----------------
0x00007fffdcd69f34      ntdll!NtWaitForSingleObject + 0x14
Locked ownable synchronizers:
    - None
----------------- 16 -----------------
0x00007fffdcd69f34      ntdll!NtWaitForSingleObject + 0x14
Locked ownable synchronizers:
    - None
----------------- 17 -----------------
0x00007fffdcd69f34      ntdll!NtWaitForSingleObject + 0x14
Locked ownable synchronizers:
    - None
----------------- 18 -----------------
0x00007fffdcd69f34      ntdll!NtWaitForSingleObject + 0x14
Locked ownable synchronizers:
    - None
----------------- 19 -----------------
0x00007fffdcd69f34      ntdll!NtWaitForSingleObject + 0x14
Locked ownable synchronizers:
    - None
----------------- 20 -----------------
0x00007fffdcd69f34      ntdll!NtWaitForSingleObject + 0x14
Locked ownable synchronizers:
    - None
----------------- 21 -----------------
Locked ownable synchronizers:
    - None
----------------- 22 -----------------
0x00007fffdcd69f34      ntdll!NtWaitForSingleObject + 0x14
----------------- 23 -----------------
0x00007fffdcd69f34      ntdll!NtWaitForSingleObject + 0x14
Locked ownable synchronizers:
    - None
----------------- 24 -----------------
0x00007fffdcd69f34      ntdll!NtWaitForSingleObject + 0x14
0x000000001fe86040              ????????
Locked ownable synchronizers:
    - None
----------------- 25 -----------------
----------------- 26 -----------------
0x00007fffdcd69f94      ntdll!ZwDeviceIoControlFile + 0x14
Locked ownable synchronizers:
    - None
----------------- 27 -----------------
0x00007fffdcd69f94      ntdll!ZwDeviceIoControlFile + 0x14
Locked ownable synchronizers:
    - None
----------------- 28 -----------------
0x00007fffdcd69f94      ntdll!ZwDeviceIoControlFile + 0x14
0x0101010101010101              ????????
Locked ownable synchronizers:
    - None
----------------- 29 -----------------
0x00007fffdcd69f34      ntdll!NtWaitForSingleObject + 0x14
Locked ownable synchronizers:
    - None
----------------- 30 -----------------
0x00007fffdcd69f94      ntdll!ZwDeviceIoControlFile + 0x14
Locked ownable synchronizers:
    - None
----------------- 31 -----------------
0x00007fffdcd69f34      ntdll!NtWaitForSingleObject + 0x14
Locked ownable synchronizers:
    - None
----------------- 32 -----------------
0x00007fffdcd69f94      ntdll!ZwDeviceIoControlFile + 0x14
Locked ownable synchronizers:
    - None
----------------- 33 -----------------
0x00007fffdcd69f34      ntdll!NtWaitForSingleObject + 0x14
0x0000000021955fd0              ????????
Locked ownable synchronizers:
    - None
----------------- 34 -----------------
0x00007fffdcd69f94      ntdll!ZwDeviceIoControlFile + 0x14
Locked ownable synchronizers:
    - None
----------------- 35 -----------------
0x00007fffdcd69f34      ntdll!NtWaitForSingleObject + 0x14
0x0000000021b56120              ????????
0x0000000000000001              ????????
sun.jvm.hotspot.debugger.DebuggerException: Windbg Error: ReadVirtual failed!
        at sun.jvm.hotspot.debugger.windbg.WindbgDebuggerLocal.readBytesFromProcess0(Native Method)
        at sun.jvm.hotspot.debugger.windbg.WindbgDebuggerLocal.readBytesFromProcess(WindbgDebuggerLocal.java:490)
        at sun.jvm.hotspot.debugger.DebuggerBase$Fetcher.fetchPage(DebuggerBase.java:80)
        at sun.jvm.hotspot.debugger.PageCache.getPage(PageCache.java:178)
        at sun.jvm.hotspot.debugger.PageCache.getLong(PageCache.java:100)
        at sun.jvm.hotspot.debugger.DebuggerBase.readCInteger(DebuggerBase.java:364)
        at sun.jvm.hotspot.debugger.DebuggerBase.readAddressValue(DebuggerBase.java:462)
        at sun.jvm.hotspot.debugger.windbg.WindbgDebuggerLocal.readAddress(WindbgDebuggerLocal.java:316)
        at sun.jvm.hotspot.debugger.windbg.WindbgAddress.getAddressAt(WindbgAddress.java:72)
        at sun.jvm.hotspot.debugger.windows.amd64.WindowsAMD64CFrame.sender(WindowsAMD64CFrame.java:60)
        at sun.jvm.hotspot.tools.PStack.run(PStack.java:161)
        at sun.jvm.hotspot.tools.PStack.run(PStack.java:58)
        at sun.jvm.hotspot.tools.PStack.run(PStack.java:53)
        at sun.jvm.hotspot.tools.JStack.run(JStack.java:66)
        at sun.jvm.hotspot.tools.Tool.startInternal(Tool.java:260)
        at sun.jvm.hotspot.tools.Tool.start(Tool.java:223)
        at sun.jvm.hotspot.tools.Tool.execute(Tool.java:118)
        at sun.jvm.hotspot.tools.JStack.main(JStack.java:92)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at sun.tools.jstack.JStack.runJStackTool(JStack.java:140)
        at sun.tools.jstack.JStack.main(JStack.java:106)
Locked ownable synchronizers:
    - None
----------------- 36 -----------------
0x00007fffdcd69f34      ntdll!NtWaitForSingleObject + 0x14
0x0000000021c55ed0              ????????
Locked ownable synchronizers:
    - None
----------------- 37 -----------------
0x00007fffdcd69f94      ntdll!ZwDeviceIoControlFile + 0x14
Locked ownable synchronizers:
    - None
----------------- 38 -----------------
0x00007fffdcd69f94      ntdll!ZwDeviceIoControlFile + 0x14
Locked ownable synchronizers:
    - None
```
@adhesivee please use `jstack <pid>`.
This is printed:
```
Debugger attached successfully.
Server compiler detected.
JVM version is 25.111-b14
Deadlock Detection:

No deadlocks found.

Thread 37: (state = IN_NATIVE)
 - sun.nio.ch.WindowsSelectorImpl$SubSelector.poll0(long, int, int[], int[], int[], long) @bci=0 (Compiled frame; information may be imprecise)
 - sun.nio.ch.WindowsSelectorImpl$SubSelector.poll() @bci=43, line=296 (Compiled frame)
 - sun.nio.ch.WindowsSelectorImpl$SubSelector.access$400(sun.nio.ch.WindowsSelectorImpl$SubSelector) @bci=1, line=278 (Compiled frame)
 - sun.nio.ch.WindowsSelectorImpl.doSelect(long) @bci=63, line=159 (Compiled frame)
 - sun.nio.ch.SelectorImpl.lockAndDoSelect(long) @bci=37, line=86 (Compiled frame)
 - sun.nio.ch.SelectorImpl.select(long) @bci=30, line=97 (Compiled frame)
 - io.netty.channel.nio.SelectedSelectionKeySetSelector.select(long) @bci=12, line=62 (Compiled frame)
 - io.netty.channel.nio.NioEventLoop.select(boolean) @bci=91, line=753 (Compiled frame)
 - io.netty.channel.nio.NioEventLoop.run() @bci=56, line=409 (Compiled frame)
 - io.netty.util.concurrent.SingleThreadEventExecutor$5.run() @bci=44, line=884 (Interpreted frame)
 - io.netty.util.concurrent.FastThreadLocalRunnable.run() @bci=4, line=30 (Interpreted frame)
 - java.lang.Thread.run() @bci=11, line=745 (Interpreted frame)


Thread 36: (state = IN_NATIVE)
 - sun.nio.ch.WindowsSelectorImpl.resetWakeupSocket0(int) @bci=0 (Compiled frame; information may be imprecise)
 - sun.nio.ch.WindowsSelectorImpl.resetWakeupSocket() @bci=22, line=473 (Compiled frame)
 - sun.nio.ch.WindowsSelectorImpl.doSelect(long) @bci=131, line=174 (Compiled frame)
 - sun.nio.ch.SelectorImpl.lockAndDoSelect(long) @bci=37, line=86 (Compiled frame)
 - sun.nio.ch.SelectorImpl.select(long) @bci=30, line=97 (Compiled frame)
 - io.netty.channel.nio.SelectedSelectionKeySetSelector.select(long) @bci=12, line=62 (Compiled frame)
 - io.netty.channel.nio.NioEventLoop.select(boolean) @bci=91, line=753 (Compiled frame)
 - io.netty.channel.nio.NioEventLoop.run() @bci=56, line=409 (Compiled frame)
 - io.netty.util.concurrent.SingleThreadEventExecutor$5.run() @bci=44, line=884 (Interpreted frame)
 - io.netty.util.concurrent.FastThreadLocalRunnable.run() @bci=4, line=30 (Interpreted frame)
 - java.lang.Thread.run() @bci=11, line=745 (Interpreted frame)


Thread 35: (state = IN_NATIVE)
 - sun.nio.ch.WindowsSelectorImpl.resetWakeupSocket0(int) @bci=0 (Compiled frame; information may be imprecise)
 - sun.nio.ch.WindowsSelectorImpl.resetWakeupSocket() @bci=22, line=473 (Compiled frame)
 - sun.nio.ch.WindowsSelectorImpl.doSelect(long) @bci=131, line=174 (Compiled frame)
 - sun.nio.ch.SelectorImpl.lockAndDoSelect(long) @bci=37, line=86 (Compiled frame)
 - sun.nio.ch.SelectorImpl.select(long) @bci=30, line=97 (Compiled frame)
 - io.netty.channel.nio.SelectedSelectionKeySetSelector.select(long) @bci=12, line=62 (Compiled frame)
 - io.netty.channel.nio.NioEventLoop.select(boolean) @bci=91, line=753 (Compiled frame)
 - io.netty.channel.nio.NioEventLoop.run() @bci=56, line=409 (Compiled frame)
 - io.netty.util.concurrent.SingleThreadEventExecutor$5.run() @bci=44, line=884 (Interpreted frame)
 - io.netty.util.concurrent.FastThreadLocalRunnable.run() @bci=4, line=30 (Interpreted frame)
 - java.lang.Thread.run() @bci=11, line=745 (Interpreted frame)


Thread 34: (state = IN_NATIVE)
 - sun.nio.ch.WindowsSelectorImpl.resetWakeupSocket0(int) @bci=0 (Compiled frame; information may be imprecise)
 - sun.nio.ch.WindowsSelectorImpl.resetWakeupSocket() @bci=22, line=473 (Compiled frame)
 - sun.nio.ch.WindowsSelectorImpl.doSelect(long) @bci=32, line=144 (Compiled frame)
 - sun.nio.ch.SelectorImpl.lockAndDoSelect(long) @bci=37, line=86 (Compiled frame)
 - sun.nio.ch.SelectorImpl.select(long) @bci=30, line=97 (Compiled frame)
 - io.netty.channel.nio.SelectedSelectionKeySetSelector.select(long) @bci=12, line=62 (Compiled frame)
 - io.netty.channel.nio.NioEventLoop.select(boolean) @bci=91, line=753 (Compiled frame)
 - io.netty.channel.nio.NioEventLoop.run() @bci=56, line=409 (Compiled frame)
 - io.netty.util.concurrent.SingleThreadEventExecutor$5.run() @bci=44, line=884 (Interpreted frame)
 - io.netty.util.concurrent.FastThreadLocalRunnable.run() @bci=4, line=30 (Interpreted frame)
 - java.lang.Thread.run() @bci=11, line=745 (Interpreted frame)


Thread 33: (state = IN_NATIVE)
 - sun.nio.ch.WindowsSelectorImpl.resetWakeupSocket0(int) @bci=0 (Compiled frame; information may be imprecise)
 - sun.nio.ch.WindowsSelectorImpl.resetWakeupSocket() @bci=22, line=473 (Compiled frame)
 - sun.nio.ch.WindowsSelectorImpl.doSelect(long) @bci=131, line=174 (Compiled frame)
 - sun.nio.ch.SelectorImpl.lockAndDoSelect(long) @bci=37, line=86 (Compiled frame)
 - sun.nio.ch.SelectorImpl.select(long) @bci=30, line=97 (Compiled frame)
 - io.netty.channel.nio.SelectedSelectionKeySetSelector.select(long) @bci=12, line=62 (Compiled frame)
 - io.netty.channel.nio.NioEventLoop.select(boolean) @bci=91, line=753 (Compiled frame)
 - io.netty.channel.nio.NioEventLoop.run() @bci=56, line=409 (Compiled frame)
 - io.netty.util.concurrent.SingleThreadEventExecutor$5.run() @bci=44, line=884 (Interpreted frame)
 - io.netty.util.concurrent.FastThreadLocalRunnable.run() @bci=4, line=30 (Interpreted frame)
 - java.lang.Thread.run() @bci=11, line=745 (Interpreted frame)


Thread 32: (state = IN_NATIVE)
 - sun.nio.ch.WindowsSelectorImpl.resetWakeupSocket0(int) @bci=0 (Compiled frame; information may be imprecise)
 - sun.nio.ch.WindowsSelectorImpl.resetWakeupSocket() @bci=22, line=473 (Compiled frame)
 - sun.nio.ch.WindowsSelectorImpl.doSelect(long) @bci=131, line=174 (Compiled frame)
 - sun.nio.ch.SelectorImpl.lockAndDoSelect(long) @bci=37, line=86 (Compiled frame)
 - sun.nio.ch.SelectorImpl.select(long) @bci=30, line=97 (Compiled frame)
 - io.netty.channel.nio.SelectedSelectionKeySetSelector.select(long) @bci=12, line=62 (Compiled frame)
 - io.netty.channel.nio.NioEventLoop.select(boolean) @bci=91, line=753 (Compiled frame)
 - io.netty.channel.nio.NioEventLoop.run() @bci=56, line=409 (Compiled frame)
 - io.netty.util.concurrent.SingleThreadEventExecutor$5.run() @bci=44, line=884 (Interpreted frame)
 - io.netty.util.concurrent.FastThreadLocalRunnable.run() @bci=4, line=30 (Interpreted frame)
 - java.lang.Thread.run() @bci=11, line=745 (Interpreted frame)


Thread 31: (state = IN_NATIVE)
 - sun.nio.ch.WindowsSelectorImpl$SubSelector.poll0(long, int, int[], int[], int[], long) @bci=0 (Compiled frame; information may be imprecise)
 - sun.nio.ch.WindowsSelectorImpl$SubSelector.poll() @bci=43, line=296 (Compiled frame)
 - sun.nio.ch.WindowsSelectorImpl$SubSelector.access$400(sun.nio.ch.WindowsSelectorImpl$SubSelector) @bci=1, line=278 (Compiled frame)
 - sun.nio.ch.WindowsSelectorImpl.doSelect(long) @bci=63, line=159 (Compiled frame)
 - sun.nio.ch.SelectorImpl.lockAndDoSelect(long) @bci=37, line=86 (Compiled frame)
 - sun.nio.ch.SelectorImpl.select(long) @bci=30, line=97 (Compiled frame)
 - io.netty.channel.nio.SelectedSelectionKeySetSelector.select(long) @bci=12, line=62 (Compiled frame)
 - io.netty.channel.nio.NioEventLoop.select(boolean) @bci=91, line=753 (Compiled frame)
 - io.netty.channel.nio.NioEventLoop.run() @bci=56, line=409 (Compiled frame)
 - io.netty.util.concurrent.SingleThreadEventExecutor$5.run() @bci=44, line=884 (Interpreted frame)
 - io.netty.util.concurrent.FastThreadLocalRunnable.run() @bci=4, line=30 (Interpreted frame)
 - java.lang.Thread.run() @bci=11, line=745 (Interpreted frame)


Thread 30: (state = IN_NATIVE)
 - sun.nio.ch.WindowsSelectorImpl$SubSelector.poll0(long, int, int[], int[], int[], long) @bci=0 (Compiled frame; information may be imprecise)
 - sun.nio.ch.WindowsSelectorImpl$SubSelector.poll() @bci=43, line=296 (Compiled frame)
 - sun.nio.ch.WindowsSelectorImpl$SubSelector.access$400(sun.nio.ch.WindowsSelectorImpl$SubSelector) @bci=1, line=278 (Compiled frame)
 - sun.nio.ch.WindowsSelectorImpl.doSelect(long) @bci=63, line=159 (Compiled frame)
 - sun.nio.ch.SelectorImpl.lockAndDoSelect(long) @bci=37, line=86 (Compiled frame)
 - sun.nio.ch.SelectorImpl.select(long) @bci=30, line=97 (Compiled frame)
 - io.netty.channel.nio.SelectedSelectionKeySetSelector.select(long) @bci=12, line=62 (Compiled frame)
 - io.netty.channel.nio.NioEventLoop.select(boolean) @bci=91, line=753 (Compiled frame)
 - io.netty.channel.nio.NioEventLoop.run() @bci=56, line=409 (Compiled frame)
 - io.netty.util.concurrent.SingleThreadEventExecutor$5.run() @bci=44, line=884 (Interpreted frame)
 - io.netty.util.concurrent.FastThreadLocalRunnable.run() @bci=4, line=30 (Interpreted frame)
 - java.lang.Thread.run() @bci=11, line=745 (Interpreted frame)


Thread 29: (state = BLOCKED)
 - sun.nio.ch.WindowsSelectorImpl.wakeup() @bci=6, line=604 (Compiled frame)
 - io.netty.channel.nio.SelectedSelectionKeySetSelector.wakeup() @bci=4, line=73 (Compiled frame)
 - io.netty.channel.nio.NioEventLoop.wakeup(boolean) @bci=20, line=708 (Compiled frame)
 - io.netty.util.concurrent.SingleThreadEventExecutor.execute(java.lang.Runnable) @bci=68, line=774 (Compiled frame)
 - io.netty.channel.AbstractChannelHandlerContext.invokeChannelReadComplete(io.netty.channel.AbstractChannelHandlerContext) @bci=46, line=391 (Compiled frame)
 - io.netty.channel.AbstractChannelHandlerContext.fireChannelReadComplete() @bci=4, line=373 (Compiled frame)
 - io.netty.channel.ChannelInboundHandlerAdapter.channelReadComplete(io.netty.channel.ChannelHandlerContext) @bci=1, line=97 (Compiled frame)
 - io.netty.channel.AbstractChannelHandlerContext.invokeChannelReadComplete() @bci=15, line=398 (Compiled frame)
 - io.netty.channel.AbstractChannelHandlerContext.invokeChannelReadComplete(io.netty.channel.AbstractChannelHandlerContext) @bci=15, line=380 (Compiled frame)
 - io.netty.channel.AbstractChannelHandlerContext.fireChannelReadComplete() @bci=4, line=373 (Compiled frame)
 - io.netty.channel.ChannelInboundHandlerAdapter.channelReadComplete(io.netty.channel.ChannelHandlerContext) @bci=1, line=97 (Compiled frame)
 - io.netty.channel.AbstractChannelHandlerContext.invokeChannelReadComplete() @bci=15, line=398 (Compiled frame)
 - io.netty.channel.AbstractChannelHandlerContext.invokeChannelReadComplete(io.netty.channel.AbstractChannelHandlerContext) @bci=15, line=380 (Compiled frame)
 - io.netty.channel.AbstractChannelHandlerContext.fireChannelReadComplete() @bci=4, line=373 (Compiled frame)
 - io.netty.channel.ChannelInboundHandlerAdapter.channelReadComplete(io.netty.channel.ChannelHandlerContext) @bci=1, line=97 (Compiled frame)
 - io.netty.channel.AbstractChannelHandlerContext.invokeChannelReadComplete() @bci=15, line=398 (Compiled frame)
 - io.netty.channel.AbstractChannelHandlerContext.invokeChannelReadComplete(io.netty.channel.AbstractChannelHandlerContext) @bci=15, line=380 (Compiled frame)
 - io.netty.channel.AbstractChannelHandlerContext.fireChannelReadComplete() @bci=4, line=373 (Compiled frame)
 - io.netty.channel.CombinedChannelDuplexHandler$DelegatingChannelHandlerContext.fireChannelReadComplete() @bci=4, line=444 (Compiled frame)
 - io.netty.handler.codec.ByteToMessageDecoder.channelReadComplete(io.netty.channel.ChannelHandlerContext) @bci=48, line=324 (Compiled frame)
 - io.netty.channel.CombinedChannelDuplexHandler.channelReadComplete(io.netty.channel.ChannelHandlerContext) @bci=43, line=263 (Compiled frame)
 - io.netty.channel.AbstractChannelHandlerContext.invokeChannelReadComplete() @bci=15, line=398 (Compiled frame)
 - io.netty.channel.AbstractChannelHandlerContext.invokeChannelReadComplete(io.netty.channel.AbstractChannelHandlerContext) @bci=15, line=380 (Compiled frame)
 - io.netty.channel.AbstractChannelHandlerContext.fireChannelReadComplete() @bci=4, line=373 (Compiled frame)
 - io.netty.channel.DefaultChannelPipeline$HeadContext.channelReadComplete(io.netty.channel.ChannelHandlerContext) @bci=1, line=1439 (Compiled frame)
 - io.netty.channel.AbstractChannelHandlerContext.invokeChannelReadComplete() @bci=15, line=398 (Compiled frame)
 - io.netty.channel.AbstractChannelHandlerContext.invokeChannelReadComplete(io.netty.channel.AbstractChannelHandlerContext) @bci=15, line=380 (Compiled frame)
 - io.netty.channel.DefaultChannelPipeline.fireChannelReadComplete() @bci=4, line=971 (Compiled frame)
 - io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read() @bci=186, line=168 (Compiled frame)
 - io.netty.channel.nio.NioEventLoop.processSelectedKey(java.nio.channels.SelectionKey, io.netty.channel.nio.AbstractNioChannel) @bci=119, line=645 (Compiled frame)
 - io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized() @bci=51, line=580 (Compiled frame)
 - io.netty.channel.nio.NioEventLoop.processSelectedKeys() @bci=8, line=497 (Compiled frame)
 - io.netty.channel.nio.NioEventLoop.run() @bci=126, line=459 (Compiled frame)
 - io.netty.util.concurrent.SingleThreadEventExecutor$5.run() @bci=44, line=884 (Interpreted frame)
 - io.netty.util.concurrent.FastThreadLocalRunnable.run() @bci=4, line=30 (Interpreted frame)
 - java.lang.Thread.run() @bci=11, line=745 (Interpreted frame)


Thread 28: (state = IN_NATIVE)
 - sun.nio.ch.WindowsSelectorImpl.resetWakeupSocket0(int) @bci=0 (Compiled frame; information may be imprecise)
 - sun.nio.ch.WindowsSelectorImpl.resetWakeupSocket() @bci=22, line=473 (Compiled frame)
 - sun.nio.ch.WindowsSelectorImpl.doSelect(long) @bci=131, line=174 (Compiled frame)
 - sun.nio.ch.SelectorImpl.lockAndDoSelect(long) @bci=37, line=86 (Compiled frame)
 - sun.nio.ch.SelectorImpl.select(long) @bci=30, line=97 (Compiled frame)
 - io.netty.channel.nio.SelectedSelectionKeySetSelector.select(long) @bci=12, line=62 (Compiled frame)
 - io.netty.channel.nio.NioEventLoop.select(boolean) @bci=91, line=753 (Compiled frame)
 - io.netty.channel.nio.NioEventLoop.run() @bci=56, line=409 (Compiled frame)
 - io.netty.util.concurrent.SingleThreadEventExecutor$5.run() @bci=44, line=884 (Interpreted frame)
 - io.netty.util.concurrent.FastThreadLocalRunnable.run() @bci=4, line=30 (Interpreted frame)
 - java.lang.Thread.run() @bci=11, line=745 (Interpreted frame)


Thread 27: (state = IN_NATIVE)
 - sun.nio.ch.WindowsSelectorImpl.resetWakeupSocket0(int) @bci=0 (Compiled frame; information may be imprecise)
 - sun.nio.ch.WindowsSelectorImpl.resetWakeupSocket() @bci=22, line=473 (Compiled frame)
 - sun.nio.ch.WindowsSelectorImpl.doSelect(long) @bci=32, line=144 (Compiled frame)
 - sun.nio.ch.SelectorImpl.lockAndDoSelect(long) @bci=37, line=86 (Compiled frame)
 - sun.nio.ch.SelectorImpl.select(long) @bci=30, line=97 (Compiled frame)
 - io.netty.channel.nio.SelectedSelectionKeySetSelector.select(long) @bci=12, line=62 (Compiled frame)
 - io.netty.channel.nio.NioEventLoop.select(boolean) @bci=91, line=753 (Compiled frame)
 - io.netty.channel.nio.NioEventLoop.run() @bci=56, line=409 (Compiled frame)
 - io.netty.util.concurrent.SingleThreadEventExecutor$5.run() @bci=44, line=884 (Interpreted frame)
 - io.netty.util.concurrent.FastThreadLocalRunnable.run() @bci=4, line=30 (Interpreted frame)
 - java.lang.Thread.run() @bci=11, line=745 (Interpreted frame)


Thread 26: (state = BLOCKED)
 - sun.nio.ch.WindowsSelectorImpl.wakeup() @bci=6, line=604 (Compiled frame)
 - io.netty.channel.nio.SelectedSelectionKeySetSelector.wakeup() @bci=4, line=73 (Compiled frame)
 - io.netty.channel.nio.NioEventLoop.wakeup(boolean) @bci=20, line=708 (Compiled frame)
 - io.netty.util.concurrent.SingleThreadEventExecutor.execute(java.lang.Runnable) @bci=68, line=774 (Compiled frame)
 - io.netty.channel.AbstractChannelHandlerContext.invokeChannelReadComplete(io.netty.channel.AbstractChannelHandlerContext) @bci=46, line=391 (Compiled frame)
 - io.netty.channel.AbstractChannelHandlerContext.fireChannelReadComplete() @bci=4, line=373 (Compiled frame)
 - io.netty.channel.ChannelInboundHandlerAdapter.channelReadComplete(io.netty.channel.ChannelHandlerContext) @bci=1, line=97 (Compiled frame)
 - io.netty.channel.AbstractChannelHandlerContext.invokeChannelReadComplete() @bci=15, line=398 (Compiled frame)
 - io.netty.channel.AbstractChannelHandlerContext.invokeChannelReadComplete(io.netty.channel.AbstractChannelHandlerContext) @bci=15, line=380 (Compiled frame)
 - io.netty.channel.AbstractChannelHandlerContext.fireChannelReadComplete() @bci=4, line=373 (Compiled frame)
 - io.netty.channel.ChannelInboundHandlerAdapter.channelReadComplete(io.netty.channel.ChannelHandlerContext) @bci=1, line=97 (Compiled frame)
 - io.netty.channel.AbstractChannelHandlerContext.invokeChannelReadComplete() @bci=15, line=398 (Compiled frame)
 - io.netty.channel.AbstractChannelHandlerContext.invokeChannelReadComplete(io.netty.channel.AbstractChannelHandlerContext) @bci=15, line=380 (Compiled frame)
 - io.netty.channel.AbstractChannelHandlerContext.fireChannelReadComplete() @bci=4, line=373 (Compiled frame)
 - io.netty.channel.ChannelInboundHandlerAdapter.channelReadComplete(io.netty.channel.ChannelHandlerContext) @bci=1, line=97 (Compiled frame)
 - io.netty.channel.AbstractChannelHandlerContext.invokeChannelReadComplete() @bci=15, line=398 (Compiled frame)
 - io.netty.channel.AbstractChannelHandlerContext.invokeChannelReadComplete(io.netty.channel.AbstractChannelHandlerContext) @bci=15, line=380 (Compiled frame)
 - io.netty.channel.AbstractChannelHandlerContext.fireChannelReadComplete() @bci=4, line=373 (Compiled frame)
 - io.netty.channel.CombinedChannelDuplexHandler$DelegatingChannelHandlerContext.fireChannelReadComplete() @bci=4, line=444 (Compiled frame)
 - io.netty.handler.codec.ByteToMessageDecoder.channelReadComplete(io.netty.channel.ChannelHandlerContext) @bci=48, line=324 (Compiled frame)
 - io.netty.channel.CombinedChannelDuplexHandler.channelReadComplete(io.netty.channel.ChannelHandlerContext) @bci=43, line=263 (Compiled frame)
 - io.netty.channel.AbstractChannelHandlerContext.invokeChannelReadComplete() @bci=15, line=398 (Compiled frame)
 - io.netty.channel.AbstractChannelHandlerContext.invokeChannelReadComplete(io.netty.channel.AbstractChannelHandlerContext) @bci=15, line=380 (Compiled frame)
 - io.netty.channel.AbstractChannelHandlerContext.fireChannelReadComplete() @bci=4, line=373 (Compiled frame)
 - io.netty.channel.DefaultChannelPipeline$HeadContext.channelReadComplete(io.netty.channel.ChannelHandlerContext) @bci=1, line=1439 (Compiled frame)
 - io.netty.channel.AbstractChannelHandlerContext.invokeChannelReadComplete() @bci=15, line=398 (Compiled frame)
 - io.netty.channel.AbstractChannelHandlerContext.invokeChannelReadComplete(io.netty.channel.AbstractChannelHandlerContext) @bci=15, line=380 (Compiled frame)
 - io.netty.channel.DefaultChannelPipeline.fireChannelReadComplete() @bci=4, line=971 (Compiled frame)
 - io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read() @bci=186, line=168 (Compiled frame)
 - io.netty.channel.nio.NioEventLoop.processSelectedKey(java.nio.channels.SelectionKey, io.netty.channel.nio.AbstractNioChannel) @bci=119, line=645 (Compiled frame)
 - io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized() @bci=51, line=580 (Compiled frame)
 - io.netty.channel.nio.NioEventLoop.processSelectedKeys() @bci=8, line=497 (Compiled frame)
 - io.netty.channel.nio.NioEventLoop.run() @bci=126, line=459 (Compiled frame)
 - io.netty.util.concurrent.SingleThreadEventExecutor$5.run() @bci=44, line=884 (Interpreted frame)
 - io.netty.util.concurrent.FastThreadLocalRunnable.run() @bci=4, line=30 (Interpreted frame)
 - java.lang.Thread.run() @bci=11, line=745 (Interpreted frame)


Thread 25: (state = BLOCKED)
 - sun.nio.ch.WindowsSelectorImpl.wakeup() @bci=6, line=604 (Compiled frame)
 - io.netty.channel.nio.SelectedSelectionKeySetSelector.wakeup() @bci=4, line=73 (Compiled frame)
 - io.netty.channel.nio.NioEventLoop.wakeup(boolean) @bci=20, line=708 (Compiled frame)
 - io.netty.util.concurrent.SingleThreadEventExecutor.execute(java.lang.Runnable) @bci=68, line=774 (Compiled frame)
 - io.netty.channel.AbstractChannelHandlerContext.invokeChannelReadComplete(io.netty.channel.AbstractChannelHandlerContext) @bci=46, line=391 (Compiled frame)
 - io.netty.channel.AbstractChannelHandlerContext.fireChannelReadComplete() @bci=4, line=373 (Compiled frame)
 - io.netty.channel.ChannelInboundHandlerAdapter.channelReadComplete(io.netty.channel.ChannelHandlerContext) @bci=1, line=97 (Compiled frame)
 - io.netty.channel.AbstractChannelHandlerContext.invokeChannelReadComplete() @bci=15, line=398 (Compiled frame)
 - io.netty.channel.AbstractChannelHandlerContext.invokeChannelReadComplete(io.netty.channel.AbstractChannelHandlerContext) @bci=15, line=380 (Compiled frame)
 - io.netty.channel.AbstractChannelHandlerContext.fireChannelReadComplete() @bci=4, line=373 (Compiled frame)
 - io.netty.channel.ChannelInboundHandlerAdapter.channelReadComplete(io.netty.channel.ChannelHandlerContext) @bci=1, line=97 (Compiled frame)
 - io.netty.channel.AbstractChannelHandlerContext.invokeChannelReadComplete() @bci=15, line=398 (Compiled frame)
 - io.netty.channel.AbstractChannelHandlerContext.invokeChannelReadComplete(io.netty.channel.AbstractChannelHandlerContext) @bci=15, line=380 (Compiled frame)
 - io.netty.channel.AbstractChannelHandlerContext.fireChannelReadComplete() @bci=4, line=373 (Compiled frame)
 - io.netty.channel.ChannelInboundHandlerAdapter.channelReadComplete(io.netty.channel.ChannelHandlerContext) @bci=1, line=97 (Compiled frame)
 - io.netty.channel.AbstractChannelHandlerContext.invokeChannelReadComplete() @bci=15, line=398 (Compiled frame)
 - io.netty.channel.AbstractChannelHandlerContext.invokeChannelReadComplete(io.netty.channel.AbstractChannelHandlerContext) @bci=15, line=380 (Compiled frame)
 - io.netty.channel.AbstractChannelHandlerContext.fireChannelReadComplete() @bci=4, line=373 (Compiled frame)
 - io.netty.channel.CombinedChannelDuplexHandler$DelegatingChannelHandlerContext.fireChannelReadComplete() @bci=4, line=444 (Compiled frame)
 - io.netty.handler.codec.ByteToMessageDecoder.channelReadComplete(io.netty.channel.ChannelHandlerContext) @bci=48, line=324 (Compiled frame)
 - io.netty.channel.CombinedChannelDuplexHandler.channelReadComplete(io.netty.channel.ChannelHandlerContext) @bci=43, line=263 (Compiled frame)
 - io.netty.channel.AbstractChannelHandlerContext.invokeChannelReadComplete() @bci=15, line=398 (Compiled frame)
 - io.netty.channel.AbstractChannelHandlerContext.invokeChannelReadComplete(io.netty.channel.AbstractChannelHandlerContext) @bci=15, line=380 (Compiled frame)
 - io.netty.channel.AbstractChannelHandlerContext.fireChannelReadComplete() @bci=4, line=373 (Compiled frame)
 - io.netty.channel.DefaultChannelPipeline$HeadContext.channelReadComplete(io.netty.channel.ChannelHandlerContext) @bci=1, line=1439 (Compiled frame)
 - io.netty.channel.AbstractChannelHandlerContext.invokeChannelReadComplete() @bci=15, line=398 (Compiled frame)
 - io.netty.channel.AbstractChannelHandlerContext.invokeChannelReadComplete(io.netty.channel.AbstractChannelHandlerContext) @bci=15, line=380 (Compiled frame)
 - io.netty.channel.DefaultChannelPipeline.fireChannelReadComplete() @bci=4, line=971 (Compiled frame)
 - io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read() @bci=186, line=168 (Compiled frame)
 - io.netty.channel.nio.NioEventLoop.processSelectedKey(java.nio.channels.SelectionKey, io.netty.channel.nio.AbstractNioChannel) @bci=119, line=645 (Compiled frame)
 - io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized() @bci=51, line=580 (Compiled frame)
 - io.netty.channel.nio.NioEventLoop.processSelectedKeys() @bci=8, line=497 (Compiled frame)
 - io.netty.channel.nio.NioEventLoop.run() @bci=126, line=459 (Compiled frame)
 - io.netty.util.concurrent.SingleThreadEventExecutor$5.run() @bci=44, line=884 (Interpreted frame)
 - io.netty.util.concurrent.FastThreadLocalRunnable.run() @bci=4, line=30 (Interpreted frame)
 - java.lang.Thread.run() @bci=11, line=745 (Interpreted frame)


Thread 24: (state = IN_NATIVE)
 - sun.nio.ch.WindowsSelectorImpl$SubSelector.poll0(long, int, int[], int[], int[], long) @bci=0 (Compiled frame; information may be imprecise)
 - sun.nio.ch.WindowsSelectorImpl$SubSelector.poll() @bci=43, line=296 (Compiled frame)
 - sun.nio.ch.WindowsSelectorImpl$SubSelector.access$400(sun.nio.ch.WindowsSelectorImpl$SubSelector) @bci=1, line=278 (Compiled frame)
 - sun.nio.ch.WindowsSelectorImpl.doSelect(long) @bci=63, line=159 (Compiled frame)
 - sun.nio.ch.SelectorImpl.lockAndDoSelect(long) @bci=37, line=86 (Compiled frame)
 - sun.nio.ch.SelectorImpl.select(long) @bci=30, line=97 (Compiled frame)
 - io.netty.channel.nio.SelectedSelectionKeySetSelector.select(long) @bci=12, line=62 (Compiled frame)
 - io.netty.channel.nio.NioEventLoop.select(boolean) @bci=91, line=753 (Compiled frame)
 - io.netty.channel.nio.NioEventLoop.run() @bci=56, line=409 (Interpreted frame)
 - io.netty.util.concurrent.SingleThreadEventExecutor$5.run() @bci=44, line=884 (Interpreted frame)
 - io.netty.util.concurrent.FastThreadLocalRunnable.run() @bci=4, line=30 (Interpreted frame)
 - java.lang.Thread.run() @bci=11, line=745 (Interpreted frame)


Thread 23: (state = BLOCKED)
 - java.lang.Object.wait(long) @bci=0 (Interpreted frame)
 - java.lang.ref.ReferenceQueue.remove(long) @bci=59, line=143 (Compiled frame)
 - io.netty.util.internal.ObjectCleaner$1.run() @bci=20, line=54 (Interpreted frame)
 - io.netty.util.concurrent.FastThreadLocalRunnable.run() @bci=4, line=30 (Interpreted frame)
 - java.lang.Thread.run() @bci=11, line=745 (Interpreted frame)


Thread 16: (state = IN_NATIVE)
 - java.net.SocketInputStream.socketRead0(java.io.FileDescriptor, byte[], int, int, int) @bci=0 (Interpreted frame)
 - java.net.SocketInputStream.socketRead(java.io.FileDescriptor, byte[], int, int, int) @bci=8, line=116 (Interpreted frame)
 - java.net.SocketInputStream.read(byte[], int, int, int) @bci=79, line=170 (Interpreted frame)
 - java.net.SocketInputStream.read(byte[], int, int) @bci=11, line=141 (Interpreted frame)
 - sun.nio.cs.StreamDecoder.readBytes() @bci=135, line=284 (Interpreted frame)
 - sun.nio.cs.StreamDecoder.implRead(char[], int, int) @bci=112, line=326 (Interpreted frame)
 - sun.nio.cs.StreamDecoder.read(char[], int, int) @bci=180, line=178 (Interpreted frame)
 - java.io.InputStreamReader.read(char[], int, int) @bci=7, line=184 (Interpreted frame)
 - java.io.BufferedReader.fill() @bci=145, line=161 (Interpreted frame)
 - java.io.BufferedReader.readLine(boolean) @bci=44, line=324 (Interpreted frame)
 - java.io.BufferedReader.readLine() @bci=2, line=389 (Interpreted frame)
 - com.intellij.rt.execution.application.AppMainV2$1.run() @bci=36, line=64 (Interpreted frame)


Thread 15: (state = BLOCKED)


Thread 14: (state = BLOCKED)


Thread 13: (state = BLOCKED)
 - java.lang.Object.wait(long) @bci=0 (Interpreted frame)
 - java.lang.ref.ReferenceQueue.remove(long) @bci=59, line=143 (Compiled frame)
 - java.lang.ref.ReferenceQueue.remove() @bci=2, line=164 (Compiled frame)
 - java.lang.ref.Finalizer$FinalizerThread.run() @bci=36, line=209 (Interpreted frame)


Thread 12: (state = BLOCKED)
 - java.lang.Object.wait(long) @bci=0 (Interpreted frame)
 - java.lang.Object.wait() @bci=2, line=502 (Compiled frame)
 - java.lang.ref.Reference.tryHandlePending(boolean) @bci=54, line=191 (Compiled frame)
 - java.lang.ref.Reference$ReferenceHandler.run() @bci=1, line=153 (Interpreted frame)


Thread 2: (state = BLOCKED)
 - java.lang.Object.wait(long) @bci=0 (Interpreted frame)
 - java.lang.Object.wait() @bci=2, line=502 (Interpreted frame)
 - io.netty.util.concurrent.DefaultPromise.await() @bci=47, line=231 (Interpreted frame)
 - io.netty.channel.DefaultChannelPromise.await() @bci=1, line=131 (Interpreted frame)
 - io.netty.channel.DefaultChannelPromise.await() @bci=1, line=30 (Interpreted frame)
 - io.netty.util.concurrent.DefaultPromise.sync() @bci=1, line=337 (Interpreted frame)
 - io.netty.channel.DefaultChannelPromise.sync() @bci=1, line=119 (Interpreted frame)
 - io.netty.channel.DefaultChannelPromise.sync() @bci=1, line=30 (Interpreted frame)
 - io.ktor.server.netty.NettyApplicationEngine.start(boolean) @bci=403, line=96 (Interpreted frame)
 - nl.myndocs.MainKt.main(java.lang.String[]) @bci=34, line=17 (Interpreted frame)
```

Pull request review comments:

Patch that resolved the issue:
diff --git a/transport/src/main/java/io/netty/channel/nio/AbstractNioMessageChannel.java b/transport/src/main/java/io/netty/channel/nio/AbstractNioMessageChannel.java
index 3d05a461841..57dcc85e584 100644
--- a/transport/src/main/java/io/netty/channel/nio/AbstractNioMessageChannel.java
+++ b/transport/src/main/java/io/netty/channel/nio/AbstractNioMessageChannel.java
@@ -172,11 +172,19 @@ protected boolean continueOnWriteError() {
     }
 
     protected boolean closeOnReadError(Throwable cause) {
-        // ServerChannel should not be closed even on IOException because it can often continue
-        // accepting incoming connections. (e.g. too many open files)
-        return cause instanceof IOException &&
-                !(cause instanceof PortUnreachableException) &&
-                !(this instanceof ServerChannel);
+        if (!isActive()) {
+            // If the channel is not active anymore for whatever reason we should not try to continue reading.
+            return true;
+        }
+        if (cause instanceof PortUnreachableException) {
+            return false;
+        }
+        if (cause instanceof IOException) {
+            // ServerChannel should not be closed even on IOException because it can often continue
+            // accepting incoming connections. (e.g. too many open files)
+            return !(this instanceof ServerChannel);
+        }
+        return true;
     }
 
     /**
diff --git a/transport/src/main/java/io/netty/channel/socket/nio/NioServerSocketChannel.java b/transport/src/main/java/io/netty/channel/socket/nio/NioServerSocketChannel.java
index 12662127c1d..f2d6f16f656 100644
--- a/transport/src/main/java/io/netty/channel/socket/nio/NioServerSocketChannel.java
+++ b/transport/src/main/java/io/netty/channel/socket/nio/NioServerSocketChannel.java
@@ -200,4 +200,10 @@ protected void autoReadCleared() {
             clearReadPending();
         }
     }
+
+    // Override just to to be able to call directly via unit tests.
+    @Override
+    protected boolean closeOnReadError(Throwable cause) {
+        return super.closeOnReadError(cause);
+    }
 }


Test patch:
diff --git a/transport/src/test/java/io/netty/channel/socket/nio/NioServerSocketChannelTest.java b/transport/src/test/java/io/netty/channel/socket/nio/NioServerSocketChannelTest.java
new file mode 100644
index 00000000000..80779902f76
--- /dev/null
+++ b/transport/src/test/java/io/netty/channel/socket/nio/NioServerSocketChannelTest.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright 2018 The Netty Project
+ *
+ * The Netty Project licenses this file to you under the Apache License,
+ * version 2.0 (the "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at:
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ */
+package io.netty.channel.socket.nio;
+
+import io.netty.channel.EventLoopGroup;
+import io.netty.channel.nio.NioEventLoopGroup;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.io.IOException;
+import java.net.InetSocketAddress;
+import java.nio.channels.ServerSocketChannel;
+
+public class NioServerSocketChannelTest {
+
+    @Test
+    public void testCloseOnError() throws Exception {
+        ServerSocketChannel jdkChannel = ServerSocketChannel.open();
+        NioServerSocketChannel serverSocketChannel = new NioServerSocketChannel(jdkChannel);
+        EventLoopGroup group = new NioEventLoopGroup(1);
+        try {
+            group.register(serverSocketChannel).syncUninterruptibly();
+            serverSocketChannel.bind(new InetSocketAddress(0)).syncUninterruptibly();
+            Assert.assertFalse(serverSocketChannel.closeOnReadError(new IOException()));
+            Assert.assertTrue(serverSocketChannel.closeOnReadError(new IllegalArgumentException()));
+            serverSocketChannel.close().syncUninterruptibly();
+        } finally {
+            group.shutdownGracefully();
+        }
+    }
+}