[ 
https://issues.apache.org/jira/browse/ARTEMIS-4654?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17819367#comment-17819367
 ] 

Justin Bertram commented on ARTEMIS-4654:
-----------------------------------------

The fundamental problem comes from underlying API which the broker uses to 
parse the connection URI. The broker uses 
[{{java.net.URI}}|https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/net/URI.html]
 which doesn't support underscores in the host. For example, this code:
{code:java}
URI uri = new URI("tcp://local_host:61616");
System.out.println(uri.getHost());
System.out.println(uri.getPort());{code}
Results in this output:
{noformat}
null
-1{noformat}
Whereas this code:
{code:java}
URI uri = new URI("tcp://local-host:61616");
System.out.println(uri.getHost());
System.out.println(uri.getPort());{code}
Results in this output:
{noformat}
local-host
61616{noformat}
The "misleading" error is categorically different from the other error you're 
seeing. The "misleading" error is fundamentally caused by a failure to parse 
the connection URI which results in a port number of {{{}-1{}}}. The other 
error is simply an inability to find the host {{local-host}} on the network 
(since the host is valid syntactically).

At this point I'm not sure what, if anything, can be done to support hosts with 
{{_}} in the connection URI. However, you should be able to work-around the 
issue by avoid the URI altogether, e.g.:
{code:java}
Map<String, Object> params = new HashMap<>();
params.put(TransportConstants.HOST_PROP_NAME, "local_host");
params.put(TransportConstants.PORT_PROP_NAME, "61616");
new ActiveMQConnectionFactory(false, new 
TransportConfiguration(NettyConnectorFactory.class.getCanonicalName(), 
params));{code}

> Misleading error message while connecting to host with underscore
> -----------------------------------------------------------------
>
>                 Key: ARTEMIS-4654
>                 URL: https://issues.apache.org/jira/browse/ARTEMIS-4654
>             Project: ActiveMQ Artemis
>          Issue Type: Bug
>          Components: Configuration
>    Affects Versions: 2.31.0
>            Reporter: Lauri Kimmel
>            Priority: Major
>
> Underscore in hostname produces unexpected error message. See details below.
> It's problematic since
>  # error message is misleading
>  # hostname with underscore is valid for certain setups. I.e in Docker 
> compose / swarm environments.
>  # underscore in hostname works for different other client libraries. Tested 
> with Postgres, InfluxDB, Redis 
> —
> Code
> {code:java}
> ActiveMQConnectionFactory factory = new 
> ActiveMQConnectionFactory("tcp://local_host:61616");
> factory.createConnection();
> {code}
> produces output
> {code:java}
> WARN  [org.apa.act.art.cor.client] (main) AMQ212007: connector.create or 
> connectorFactory.createConnector should never throw an exception, 
> implementation is badly behaved, but we will deal with it anyway.: 
> java.lang.IllegalArgumentException: port out of range:-1
>     at 
> java.base/java.net.InetSocketAddress.checkPort(InetSocketAddress.java:152)
>     at java.base/java.net.InetSocketAddress.<init>(InetSocketAddress.java:233)
>     at 
> org.apache.activemq.artemis.core.remoting.impl.netty.NettyConnector.createConnection(NettyConnector.java:874)
>     at 
> org.apache.activemq.artemis.core.remoting.impl.netty.NettyConnector.createConnection(NettyConnector.java:866)
>     at 
> org.apache.activemq.artemis.core.remoting.impl.netty.NettyConnector.createConnection(NettyConnector.java:848)
>     at 
> org.apache.activemq.artemis.core.client.impl.ClientSessionFactoryImpl.openTransportConnection(ClientSessionFactoryImpl.java:1212)
>     at 
> org.apache.activemq.artemis.core.client.impl.ClientSessionFactoryImpl.createTransportConnection(ClientSessionFactoryImpl.java:1333)
>     at 
> org.apache.activemq.artemis.core.client.impl.ClientSessionFactoryImpl.createTransportConnection(ClientSessionFactoryImpl.java:1253)
>     at 
> org.apache.activemq.artemis.core.client.impl.ClientSessionFactoryImpl.establishNewConnection(ClientSessionFactoryImpl.java:1496)
>     at 
> org.apache.activemq.artemis.core.client.impl.ClientSessionFactoryImpl.getConnection(ClientSessionFactoryImpl.java:1074)
>     at 
> org.apache.activemq.artemis.core.client.impl.ClientSessionFactoryImpl.getConnectionWithRetry(ClientSessionFactoryImpl.java:959)
>     at 
> org.apache.activemq.artemis.core.client.impl.ClientSessionFactoryImpl.connect(ClientSessionFactoryImpl.java:279)
>     at 
> org.apache.activemq.artemis.core.client.impl.ClientSessionFactoryImpl.connect(ClientSessionFactoryImpl.java:295)
>     at 
> org.apache.activemq.artemis.core.client.impl.ServerLocatorImpl.createSessionFactory(ServerLocatorImpl.java:709)
>     at 
> org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory.createConnectionInternal(ActiveMQConnectionFactory.java:865)
>     at 
> org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory.createConnection(ActiveMQConnectionFactory.java:284)
>     at 
> org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory.createConnection(ActiveMQConnectionFactory.java:279)
>     ...
> {code}
> while code 
> {code:java}
> ActiveMQConnectionFactory factory = new 
> ActiveMQConnectionFactory("tcp://local-host:61616");
> factory.createConnection();
> {code}
> produces output
> {code:java}
> ERROR [org.apa.act.art.cor.client] (main) AMQ214016: Failed to create netty 
> connection: java.net.UnknownHostException: local-host
>     at 
> java.base/java.net.InetAddress$CachedAddresses.get(InetAddress.java:801)
>     at java.base/java.net.InetAddress.getAllByName0(InetAddress.java:1509)
>     at java.base/java.net.InetAddress.getAllByName(InetAddress.java:1367)
>     at java.base/java.net.InetAddress.getAllByName(InetAddress.java:1301)
>     at java.base/java.net.InetAddress.getByName(InetAddress.java:1251)
>     at io.netty.util.internal.SocketUtils$8.run(SocketUtils.java:156)
>     at io.netty.util.internal.SocketUtils$8.run(SocketUtils.java:153)
>     at 
> java.base/java.security.AccessController.doPrivileged(AccessController.java:569)
>     at io.netty.util.internal.SocketUtils.addressByName(SocketUtils.java:153)
>     at 
> io.netty.resolver.DefaultNameResolver.doResolve(DefaultNameResolver.java:41)
>     at 
> io.netty.resolver.SimpleNameResolver.resolve(SimpleNameResolver.java:61)
>     at 
> io.netty.resolver.SimpleNameResolver.resolve(SimpleNameResolver.java:53)
>     at 
> io.netty.resolver.InetSocketAddressResolver.doResolve(InetSocketAddressResolver.java:55)
>     at 
> io.netty.resolver.InetSocketAddressResolver.doResolve(InetSocketAddressResolver.java:31)
>     at 
> io.netty.resolver.AbstractAddressResolver.resolve(AbstractAddressResolver.java:106)
>     at io.netty.bootstrap.Bootstrap.doResolveAndConnect0(Bootstrap.java:206)
>     at io.netty.bootstrap.Bootstrap.access$000(Bootstrap.java:46)
>     at io.netty.bootstrap.Bootstrap$1.operationComplete(Bootstrap.java:180)
>     at io.netty.bootstrap.Bootstrap$1.operationComplete(Bootstrap.java:166)
>     at 
> io.netty.util.concurrent.DefaultPromise.notifyListener0(DefaultPromise.java:590)
>     at 
> io.netty.util.concurrent.DefaultPromise.notifyListenersNow(DefaultPromise.java:557)
>     at 
> io.netty.util.concurrent.DefaultPromise.notifyListeners(DefaultPromise.java:492)
>     at 
> io.netty.util.concurrent.DefaultPromise.setValue0(DefaultPromise.java:636)
>     at 
> io.netty.util.concurrent.DefaultPromise.setSuccess0(DefaultPromise.java:625)
>     at 
> io.netty.util.concurrent.DefaultPromise.trySuccess(DefaultPromise.java:105)
>     at 
> io.netty.channel.DefaultChannelPromise.trySuccess(DefaultChannelPromise.java:84)
>     at 
> io.netty.channel.AbstractChannel$AbstractUnsafe.safeSetSuccess(AbstractChannel.java:990)
>     at 
> io.netty.channel.AbstractChannel$AbstractUnsafe.register0(AbstractChannel.java:516)
>     at 
> io.netty.channel.AbstractChannel$AbstractUnsafe.access$200(AbstractChannel.java:429)
>     at 
> io.netty.channel.AbstractChannel$AbstractUnsafe$1.run(AbstractChannel.java:486)
>     at 
> io.netty.util.concurrent.AbstractEventExecutor.runTask(AbstractEventExecutor.java:174)
>     at 
> io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:167)
>     at 
> io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:470)
>     at io.netty.channel.epoll.EpollEventLoop.run(EpollEventLoop.java:406)
>     at 
> io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:997)
>     at 
> io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
>     at 
> org.apache.activemq.artemis.utils.ActiveMQThreadFactory$1.run(ActiveMQThreadFactory.java:118){code}
>  



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to