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

Failed to bind to '::/[0:0:0:0:0:0:0:0]:5076'. #130

Open
pjyoung opened this issue Mar 30, 2023 · 2 comments
Open

Failed to bind to '::/[0:0:0:0:0:0:0:0]:5076'. #130

pjyoung opened this issue Mar 30, 2023 · 2 comments
Assignees

Comments

@pjyoung
Copy link

pjyoung commented Mar 30, 2023

After upgrading to openjdk 19.0.2, my code that uses pvAccessJava 5.1.7 fails when trying to
channelProvider = ChannelProviderRegistryFactory.getChannelProviderRegistry().getProvider(ClientFactory.PROVIDER_NAME);
this throws a ConnectionException with message "Failed to bind to '::/[0:0:0:0:0:0:0:0]:5076'." The call stack is:

ClientContextImpl.initializeUDPTransport:482
ClientContextImpl.internalInitialize:408
ClientContextImpl.initialize:372
GhostClientFactory$GhostChannelProviderFactoryImpl.sharedInstance:43
ChannelProviderRegistryFactory$ChannelProviderRegistryImpl.getProvider:51

The same code works fine with openjdk 17.0.2 and earlier (using same host environment). My host OS is MacOS Ventura 13.2 on a MacBook Pro 14 M2 - so the architecture is aarch64.

Anyone else seen this?

Thanks Peter

@pjyoung
Copy link
Author

pjyoung commented Mar 30, 2023

Managed to code a workaround:

     <name>pvAccessJava</name>
     <url>https://github.com/epics-base/pvAccessJava</url>
diff --git a/pvAccessJava/src/org/epics/pvaccess/client/impl/remote/ClientContextImpl.java b/pvAccessJava/src/org/epics/pvaccess/client/impl/remote/ClientContextImpl.java
index 87d20d48..640a80ec 100644
--- a/pvAccessJava/src/org/epics/pvaccess/client/impl/remote/ClientContextImpl.java
+++ b/pvAccessJava/src/org/epics/pvaccess/client/impl/remote/ClientContextImpl.java
@@ -20,6 +20,7 @@ import java.net.InetAddress;
 import java.net.InetSocketAddress;
 import java.net.NetworkInterface;
 import java.net.SocketException;
+import java.net.UnknownHostException;
 import java.nio.channels.SocketChannel;
 import java.util.ArrayList;
 import java.util.Collections;
@@ -418,7 +419,7 @@ public class ClientContextImpl implements Context {
                // setup UDP transport
                try {
                        // where to bind (listen) address
-                       InetSocketAddress listenLocalAddress = new InetSocketAddress(broadcastPort);
+                       InetSocketAddress listenLocalAddress = new InetSocketAddress(InetAddress.getByName("0.0.0.0"), broadcastPort);
 
                        // where to send address
                        InetSocketAddress[] broadcastAddresses = InetAddressUtil.getBroadcastAddresses(broadcastPort);
@@ -432,7 +433,7 @@ public class ClientContextImpl implements Context {
                        BlockingUDPConnector searchConnector = new BlockingUDPConnector(this, false, broadcastAddresses, true);
 
                        searchTransport = (BlockingUDPTransport) searchConnector.connect(null, new ClientResponseHandler(this),
-                                       new InetSocketAddress(0), PVAConstants.PVA_PROTOCOL_REVISION, PVAConstants.PVA_DEFAULT_PRIORITY);
+                                       new InetSocketAddress(InetAddress.getByName("0.0.0.0"), 0), PVAConstants.PVA_PROTOCOL_REVISION, PVAConstants.PVA_DEFAULT_PRIORITY);
 
                        // set broadcast address list
                        if (addressList != null && addressList.length() > 0) {
@@ -478,9 +479,9 @@ public class ClientContextImpl implements Context {
                        broadcastTransport.start();
                        searchTransport.start();
 
-               } catch (ConnectionException ce) {
+               } catch (ConnectionException  | UnknownHostException ce) {
                        logger.log(Level.SEVERE, "Failed to initialize UDP transport.", ce);
-               }
+          }
        }
 
        /*

It's interesting that the InetSocketAddress call returns an ipv6 address given ipv6 is disabled on the host and I note that the error doesn't occur if I run the examples in (eg exampleJava/exampleClient). The difference I note is that in my code we actually do some calls to connect to CA channels using the CAJ library and if one steps through the InetSocketAddress code, the init code below (from InetAddress.java) is called first via CAJ:

   _static {
        // create the impl
        impl = isIPv6Supported() ?
                new Inet6AddressImpl() : new Inet4AddressImpl();

        // impl must be initialized before calling this method
        PLATFORM_LOOKUP_POLICY = initializePlatformLookupPolicy();

        // create built-in resolver
        BUILTIN_RESOLVER = createBuiltinInetAddressResolver();
    }_

and the impl instance is set to Inet6AddressImpl. Whereas in the example this code is first called from the pvAccess library and impl is set to Inet4AddressImpl. So what is the difference? How is ipv6 suppressed in the example code? And why, when CAJ executes this code first, ipv6 is enabled?

@kasemir
Copy link
Contributor

kasemir commented Sep 18, 2024

Can you try to run the existing code with export JDK_JAVA_OPTIONS=-Djava.net.preferIPv4Stack=true ?

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