Pulsar: URI("pulsar://broker-:6650").getPort() will return "-1" instead of 6650

Created on 3 Jan 2018  路  6Comments  路  Source: apache/pulsar

found this by wrongly set hostname to "broker-", while using docker to do some test, not sure if this is a bug in java.net.URI.
while after change hostname to "broker-1", it worked fine to get 6650.

Expected behavior

In this part of code,

   public BrokerService(PulsarService pulsar) throws Exception {
        this.pulsar = pulsar;
        this.managedLedgerFactory = pulsar.getManagedLedgerFactory();
        this.port = new URI(pulsar.getBrokerServiceUrl()).getPort();
        this.tlsPort = new URI(pulsar.getBrokerServiceUrlTls()).getPort();
...

URI("pulsar://broker-:6650").getPort() should return 6650

Actual behavior

URI("pulsar://broker-:6650").getPort() will return "-1"

Steps to reproduce

set hostname to "broker-", start broker on this host, it will report wrong port:

2018-01-03 02:13:14,778 - INFO  - [main:DistributedIdGenerator@79] - Created sequential node at /counters/producer-name/-0000000000 -- Generator Id is test_zj-0
2018-01-03 02:13:14,781 - ERROR - [main:PulsarService@345] - port out of range:-1
java.lang.IllegalArgumentException: port out of range:-1
    at java.net.InetSocketAddress.checkPort(InetSocketAddress.java:143)
    at java.net.InetSocketAddress.<init>(InetSocketAddress.java:224)
    at org.apache.pulsar.broker.service.BrokerService.start(BrokerService.java:285)
    at org.apache.pulsar.broker.PulsarService.start(PulsarService.java:270)
    at org.apache.pulsar.PulsarBrokerStarter$BrokerStarter.start(PulsarBrokerStarter.java:190)

the docker command that I wrongly set hostname is this:

docker run -it\
        --network pulsar_network \
        --volume /tmp/test_bk/broker-/journal:/data/journal \
        --volume /tmp/test_bk/broker-/ledger:/data/ledger \
        --volume /tmp/test_bk/broker-/index:/data/index \
        --name "broker-" \
        --hostname "broker-" \
        --env zkServers=192.168.123.71:2181 \
        --env zookeeperServers=192.168.123.71:2181 \
        --env globalZookeeperServers=192.168.123.71:2181 \
        --env clusterName=test_zhaijia \
        --env statsProviderClass=org.apache.bookkeeper.stats.NullStatsProvider \
        --env zkLedgersRootPath=/ledgers \
            bin/apply-config-from-env.py conf/broker.conf &&  bin/apply-config-from-env.py conf/pulsar_env.sh && bin/apply-config-from-env.py conf/bookkeeper.conf  && bin/pulsar broker
componenclient typbug

Most helpful comment

as discussed, we might consider documenting what special characters can't be used in pulsar service uri.

All 6 comments

as discussed, we might consider documenting what special characters can't be used in pulsar service uri.

let's try improve error handling and produce meaningful message if we can't get around with the java URL api.

@zhaijack can you work on this? since it has been there for a while. it should be a simple fix.

It seems I cannot use '_' in host.
(new URI("pulsar://tkiot_pulsar1:6650")).getPort() returns -1

I found this useful link.
https://bugs.java.com/bugdatabase/view_bug.do?bug_id=5049974

@ppgoml yes it is a problem from java's URI

Closed this issue since it is a problem in the URI.

Was this page helpful?
0 / 5 - 0 ratings