epics-base / epicsCoreJava

Parent repository for building, bundling, and deploying the EPICS Core Java libraries
Other
7 stars 10 forks source link

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

Open pjyoung opened 1 year ago

pjyoung commented 1 year ago

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 commented 1 year ago

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

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?