netty / netty

Netty project - an event-driven asynchronous network application framework
http://netty.io
Apache License 2.0
33.93k stars 16.04k forks source link

IoUring:Cant accept more connection When isIOUringAcceptMultishotSupported is true #14819

Closed dreamlike-ocean closed 1 month ago

dreamlike-ocean commented 1 month ago

I used the code from the 4.2 branch for testing and found that when isIOUringAcceptMultishotSupported is true, after accepting some connections, no more connections can be received.

When I modified the netty4.2 code and changed isIOUringAcceptMultishotSupported to false, everything returned to normal.

single git:(master) ✗ uname -a
Linux dreamlike-MS-7E01 6.11.0-14-generic #15-Ubuntu SMP PREEMPT_DYNAMIC Fri Jan 10 23:48:25 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux

➜  single git:(master) ✗ mvn -v                                                         
Apache Maven 3.9.4 (dfbb324ad4a7c8fb0bf182e6d91b0ae20e3d2dd9)
Maven home: /home/dreamlike/.sdkman/candidates/maven/current
Java version: 17.0.1, vendor: Oracle Corporation, runtime: /home/dreamlike/jdks/openjdk-17.0.1_linux-x64_bin/jdk-17.0.1
Default locale: zh_CN, platform encoding: UTF-8
OS name: "linux", version: "6.11.0-14-generic", arch: "amd64", family: "unix"

The Test code

      IoHandlerFactory ioHandlerFactory = IoUringIoHandler.newFactory();
        MultiThreadIoEventLoopGroup boss = new MultiThreadIoEventLoopGroup(1, ioHandlerFactory);

        ServerBootstrap serverBootstrapBase = new ServerBootstrap()
                .group(boss, boss)
                .option(IoUringChannelOption.SO_BACKLOG, 10240)
                .channel(IoUringServerSocketChannel.class)
                .childHandler(new SimpleChannelInboundHandler<ByteBuf>() {

                    @Override
                    protected void channelRead0(ChannelHandlerContext ctx, ByteBuf msg) throws Exception {
                        //just drop
                    }

                    @Override
                    public boolean isSharable() {
                        return true;
                    }
                });
        ServerChannel channel = ((ServerChannel) serverBootstrapBase.bind("0.0.0.0", 4399)
                .sync()
                .channel());

        for (int i = 0; i < 10240; i++) {
            new Socket()
                    .connect(channel.localAddress());
            System.out.println("connection end: "+ i);
        }

I'm also debugging the corresponding source code. I suspect that this section of code is the cause.

//AbstractIoUringChannel::readComplete
  } else if (!readPending) {
                        // Cancel the multi-shot read now as the user did not signal that we want to keep reading.
                        cancelOutstandingReads(registration, numOutstandingReads);
                        ioState &= ~READ_SCHEDULED;
                    }
normanmaurer commented 1 month ago

Can you try with this pr:

https://github.com/netty/netty/pull/14818

This fixes some issues that also affect the accept code path

dreamlike-ocean commented 1 month ago

Good. I run the code from this PR and it seems to be working fine. I'll close this issue for now.