question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Lots of warnings: Selector.select() returned prematurely 512 times in a row; rebuilding Selector io.netty.channel.nio.SelectedSelectionKeySetSelector@6edf74c3 after network issue.

See original GitHub issue

Expected behavior

no issues

Actual behavior

We use Netty for message exchange between two internal systems. The system is running smoothly for months. After a network incident (inbound / outbound communication was affected) we’ve suddenly seen a lot of warning messages in our logs. We are running 4 machines, all are equal to each other. Nearly a the same time all machines got the same behavior.

Each system was the message logging nearly 60k times per minute Selector.select() returned prematurely 512 times in a row; rebuilding Selector io.netty.channel.nio.SelectedSelectionKeySetSelector@6edf74c3

When we restarted the Event loops (but not the JVM) the problem went away. The thread that is logging the warnings is the one that is responsible for sending out the response to the remote peer

This is, what we are actually doing:

receivingGroup = new NioEventLoopGroup(protocolServerConfiguration.getReceivingThreadSize(), receivingExecutors);
        respondingGroup = new NioEventLoopGroup(protocolServerConfiguration.getRespondingThreadSize(), respondingExecutors);
        serverBootstrap = new ServerBootstrap();
        serverBootstrap.group(receivingGroup, respondingGroup);
        serverBootstrap.channel(NioServerSocketChannel.class);
        serverBootstrap.childHandler(new ChunkedChannelInitializer());
...
protected void initChannel(SocketChannel socketChannel) {
    String remoteHostname = socketChannel.remoteAddress().getHostName();
    LOGGER.debug("New client connection from: {}.", remoteHostname);
    // read and parse the message from the remote peer
    ChannelInboundHandlerAdapter channelRequestInboundHandlerAdapter = new ChannelRequestInboundHandlerAdapter();
    socketChannel.pipeline().addLast(channelRequestInboundHandlerAdapter);            
}

// after the message is successfully parsed, we send the response
...
public ChannelFuture sendResponse(byte[] responseMessageBytes) {
    ByteBuf byteBuf = ByteBufAllocator.DEFAULT.heapBuffer(responseMessageBytes.length);
    byteBuf.writeBytes(responseMessageBytes);
    socketChannel.writeAndFlush(byteBuf);
    return socketChannel.close();
}

When the issue occurred the CPU usage went up to 100 percent on all machines.

Maybe this is related to #8698.

Steps to reproduce

We could not reproduce it. The system run for weeks without issues. Then the issue suddenly occurred. After restart it was gone again.

Minimal yet complete reproducer code (or URL to code)

Netty version

4.1.42.Final

JVM version (e.g. java -version)

OpenJDK 64-Bit Server VM (Zulu 8.48.0.52-SA-linux64) (build 25.262-b19, mixed mode)

OS version (e.g. uname -a)

Linux 3.10.0-1160.11.1.el7.x86_64 #1 SMP Mon Nov 30 13:05:31 EST 2020 x86_64 x86_64 x86_64 GNU/Linux

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

5reactions
PabloFioricommented, Aug 19, 2021

For using Netty on Android where epoll doesn’t seem to work, is there any way to work around this @normanmaurer? I currently repro this with 100% consistency right now. I also double checked to make sure that there aren’t any memory leaks in our code. I unfortunately cannot share a reproducer.

3reactions
mnm364commented, Aug 23, 2021

@PabloFiori this seems concerning, especially considering that Netty 4.1 claims to support Android >4.0 but this seems like a non-starter to use Netty to manage NIO-selectors. I wonder if there are grounds here to file an issue branching off of this discussion; this is also something I have run into.

[UPDATE] In fact, it seems this issue has come up already but was rejected as a change in https://github.com/netty/netty/pull/10881. 😕

Read more comments on GitHub >

github_iconTop Results From Across the Web

Selector.select() returned prematurely 512 times in a row #8698
Lots of warnings: Selector.select() returned prematurely 512 times in a row; rebuilding Selector io.netty.channel.nio.
Read more >
Netty 4: NioEventLoop rebuild selector too often - Stack Overflow
NioEventLoop ] Selector.select() returned prematurely 512 times in a row; rebuilding selector. 09:22:47,576 [TRACE pGroup-3-1 netty.channel.nio ...
Read more >
WARN io.netty.channel.nio.NioEventLoop - Google Groups
nio.NioEventLoop - Selector.select() returned prematurely 512 times in a row; rebuilding Selector io.netty.channel.nio.SelectedSelectionKeySetSelector@6ef45be.
Read more >
A lot of WARN from NioEventLoop: Selector.selec... - JBoss.org
select() returned prematurely 512 times in a row; rebuilding selector. 15:38:51,694 INFO [io.netty.channel.nio.NioEventLoop] Migrated 0 channel( ...
Read more >
What does this warning mean? Selector return prematurely
I have nodejs server that is trying to push alot of docs into elasticsearch ... Selector.select() returned prematurely 512 times in a row; ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found