Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with libudx ipv6 socket and docker containers #130

Open
riccardobl opened this issue Jan 18, 2023 · 2 comments
Open

Issue with libudx ipv6 socket and docker containers #130

riccardobl opened this issue Jan 18, 2023 · 2 comments

Comments

@riccardobl
Copy link

riccardobl commented Jan 18, 2023

I am currently investigating an issue with Hyperswarm, where it is unable to establish a connection between two Docker containers running on different machines on different networks and connected to their respective "bridge" interface (note: when one of the two machines uses "--network host" the connection is established, but this workaround is undesirable for several reasons).

The issue seems to be caused by libudx defaulting to binding to an IPv6 socket, which works within the containers but causes incoming packets to be dropped.

This may be due to IPv6 being disabled by default on the Docker daemon.

By forcing the use of IPv4 in the code below, the issue can be resolved.
If IPv6 needs to be the default, i think a flag should be added to the library, allowing the software using it to force IPv4 when running on platforms with this issue.

libudx/lib/socket.js

Lines 133 to 141 in 9a1760a

try {
host = '::'
family = 6
this._port = binding.udx_napi_socket_bind(this._handle, port, host, family)
} catch {
host = '0.0.0.0'
family = 4
this._port = binding.udx_napi_socket_bind(this._handle, port, host, family)
}

@riccardobl
Copy link
Author

For others facing a similar problem: this is a workaround to forcefully disable IPv6 on the current version of libudx from the application code without modifying the library

import UDXBinding from "udx-native/lib/binding.js";
function disableIPv6(){
    const _udx_napi_socket_bind=UDXBinding.udx_napi_socket_bind;
    UDXBinding.udx_napi_socket_bind=function(...args){
        if(args[3]==6) throw "IPv6 is disabled"        
        _udx_napi_socket_bind(...args);
    }
}
disableIPv6();

@kasperisager
Copy link
Contributor

I haven't been able to replicate the @hyperswarm/doctor results you posted in Discord, I'm consistently getting a Peer not found error even if only binding to IPv4. However, disabling all the IPv6-only tests in libudx makes everything pass as expected so the default dual-stack bind appears to work 🤔 That is, by binding to all available IPv6 and IPv4 addresses, which is what the "any" address :: will do, IPv4 traffic goes through just fine while IPv6 traffic times out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants