diff --git a/transport-sctp/src/main/java/io/netty/channel/sctp/oio/OioSctpChannel.java b/transport-sctp/src/main/java/io/netty/channel/sctp/oio/OioSctpChannel.java index f0a1ccac8f..830f3aef7c 100755 --- a/transport-sctp/src/main/java/io/netty/channel/sctp/oio/OioSctpChannel.java +++ b/transport-sctp/src/main/java/io/netty/channel/sctp/oio/OioSctpChannel.java @@ -183,7 +183,12 @@ public class OioSctpChannel extends AbstractOioMessageChannel if (!keysSelected) { return readMessages; } - + // We must clear the selectedKeys because the Selector will never do it. If we do not clear it, the selectionKey + // will always be returned even if there is no data can be read which causes performance issue. And in some + // implementation of Selector, the select method may return 0 if the selectionKey which is ready for process has + // already been in the selectedKeys and cause the keysSelected above to be false even if we actually have + // something to read. + readSelector.selectedKeys().clear(); final RecvByteBufAllocator.Handle allocHandle = unsafe().recvBufAllocHandle(); ByteBuf buffer = allocHandle.allocate(config().getAllocator()); boolean free = true;