URI("pulsar://broker-:6650").getPort() will return "-1" instead of 6650
See original GitHub issuefound 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
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (5 by maintainers)
Top Results From Across the Web
How to get the port from IPv6 Uri? - Stack Overflow
getPort() returns -1 instead of 1234. How can the port of a Uri obtained without parsing the Uri's string? android · android-networking.
Read more >java.net.URI.getPort java code examples - Tabnine
Returns the port number of this URI, or -1 if this URI has no explicit port. Popular methods of URI. <init>. Constructs a...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
as discussed, we might consider documenting what special characters can’t be used in pulsar service uri.
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