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.

binding an ipv6 address on an epoll channel when ipv6 is disabled "succeeds"

See original GitHub issue

Expected behavior

Trying to bind an IPv6 address if IPv6 is disable on the system should fail.

Actual behavior

The program silently binds the wrong port.

Steps to reproduce

Run the code below after sysctl net.ipv6.conf.all.disable_ipv6=0. When nio is used, the program fails with an expected exception:

Exception in thread "main" java.net.SocketException: Protocol family unavailable
	at sun.nio.ch.Net.bind0(Native Method)
	at sun.nio.ch.Net.bind(Net.java:433)
	at sun.nio.ch.Net.bind(Net.java:425)

When epoll is enabled, the program binds IPv4 0.0.0.1!

Minimal yet complete reproducer code (or URL to code)

import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.*;
import io.netty.channel.epoll.*;
import io.netty.channel.nio.*;
import io.netty.channel.socket.SocketChannel;
import io.netty.channel.socket.nio.*;
import java.net.InetSocketAddress;

public class Example {
  public static void main(String[] args) throws Exception {
    EventLoopGroup bossGroup;
    EventLoopGroup workerGroup;
    Class clazz;
    if (args.length > 1) {
      bossGroup = new EpollEventLoopGroup(1);
      workerGroup = new EpollEventLoopGroup();
      clazz = EpollServerSocketChannel.class;
    } else {
      bossGroup = new NioEventLoopGroup(1);
      workerGroup = new NioEventLoopGroup();
      clazz = NioServerSocketChannel.class;
    }

    ServerBootstrap b = new ServerBootstrap();
    b.group(bossGroup, workerGroup)
        .channel(clazz)
        .childHandler(
            new ChannelInitializer<SocketChannel>() {
              @Override
              public void initChannel(SocketChannel ch) throws Exception {}
            });

    ChannelFuture f = b.bind(new InetSocketAddress("[::1]", 0)).sync();
    f.channel().closeFuture().sync();
  }
}

Netty version

4.1.51

JVM version (e.g. java -version)

8

OS version (e.g. uname -a)

Linux

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:12 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
normanmaurercommented, Jul 17, 2020

@benjaminp @meteorcloudy thanks for the reproducer… This should be fixed by https://github.com/netty/netty/pull/10415

1reaction
normanmaurercommented, Jul 14, 2020

This sounds unexpected… I will try to have a look soon. That said if you have time and want to contribute I am happy to review a PR as well

Read more comments on GitHub >

github_iconTop Results From Across the Web

Epoll socket channel creates a listener on IPv6 and not IPv4
While creating a server channel (even if I am binding it to an IPv4 address) I see in netstat that the port is...
Read more >
Guidance for configuring IPv6 in Windows for advanced users
Provides step-by-step guidance for how to use the Windows registry to disable IPv6 or certain IPv6 components in Windows.
Read more >
Networking | Elasticsearch Guide [8.5] | Elastic
Elasticsearch can only bind to an address if it is running on a host that has a network interface with that address. If...
Read more >
microhttpd-const (The GNU libmicrohttpd Reference Manual)
Run using an internal thread doing SELECT . MHD_USE_IPv6. Run using the IPv6 protocol (otherwise, MHD will just support IPv4). If you specify...
Read more >
Binding an IPv6 server socket on Windows - Stack Overflow
The only supported way to create an IPv6 server socket channel is to create ... an IPv6 address when IPv6 is not available,...
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